PHP Classes

Assumes 2-char codes?

Recommend this page to a friend!

      Add multiple languages to a Web  >  All threads  >  Assumes 2-char codes?  >  (Un) Subscribe thread alerts  
Subject:Assumes 2-char codes?
Summary:detectLanguage appears to assume all lang codes are 2 chars
Messages:1
Author:Dan Franklin
Date:2009-01-16 15:59:55
 

  1. Assumes 2-char codes?   Reply   Report abuse  
Picture of Dan Franklin Dan Franklin - 2009-01-16 15:59:55
We're starting to internationalize one of our websites, so I was very interested in this class when it appeared. I think there is a problem with the detectLanguage function. The line

$this->language = substr($this->languages,0,2);

appears to assume that all language codes are 2 characters long. In fact some language codes can be 3 characters long. See BCP47 ( http://www.rfc-editor.org/rfc/bcp/bcp47.txt ).

This assumption may be in other parts of this function as well - I see other "2"s in there.

It would be better to take the first string up to a '-' (or for some weird browsers, a '_' as well) to choose the language.

Thanks for providing the class!

Dan