In i18n.module, i18n_get_browser_lang(), I've commented the line:
/*$lang=substr($lang,0,2);*/
so that browser detection will work for Chinese language codes (zh-tw, zh-cn, etc.) which is longer than 2 chars.

Is it possible to be made to the official release (perhaps with some further tweaks)?

Many thks,
Peter.

Comments

josesanmartin’s picture

Hello!

I had troubles with this issue, too.
I have written a patch, that covers another situations.

In my website, I have three languages: "en-us", "pt-br" and "de". The patch below allows webbrowsers configured with "en", "en-ja", "en-gb" to be redirected to "en-us".

 function i18n_get_browser_lang() {
 $languages = i18n_supported_languages();
 // begin PATCH
 $aliases = array();
 foreach ($languages as $lang => $name) {
   if (strlen($lang) > 2)
     $aliases[substr($lang,0,2)] = $lang;
 }
 // end PATCH
 $exploded_server = explode(";",$_SERVER["HTTP_ACCEPT_LANGUAGE"]);
 $accept=explode(',',array_shift($exploded_server));
 foreach ($accept as $lang) {
   $lang=substr($lang,0,2);
   if ( !empty($lang) && array_key_exists($lang, $languages)) {
     return $lang;
   }
   // begin PATCH
   if ( !empty($lang) && array_key_exists($lang, $aliases)) {
     return $aliases[$lang];
   }
   // end PATCH
 }
}

Regards,

José San Martín

mine@subnet142.com’s picture

Hi, thanks for the speedy response. I am not really familiar with PHP and Drupal internals... Just one query - what about if you also have "en-ja" set up in addition to "en-us" on your website, then would the patched browser detection returns "en-ja" or "en-us"?

marc.bau’s picture

one thing i learned in the last months is. Browser detection is a no-no. thing about spiders... they are detected as english. So if you prefer to get ranked in a chinese or other non english language search engine - deactivate it...

mine@subnet142.com’s picture

For the search engine behavior, I ain't sure but perhaps it can be mitigated by submitting http://site/zh-cn, http://site/zh-tw, http://site/en... etc. to the search engines?

What worries me more is still whether "zh-tw" and "zh-cn" will be "generalized" to one language, say "zh-cn" by the browser detection logic.  Unlike the various "en" flavors, "zh-tw" and "zh-cn" is very different - they have different character sets and glyphs.

Not being a real PHP coder myself, I ain't sure whether the code above by Jose will do this "generalization".  Jose, very much appreciate your further comments.

Many thks.

jose reyero’s picture

Agree that we could use some better browser language detection algorithm... However I'm not sure about the Chinese language variations mentioned here and also would like some real fall-back mechanism for languages. So giving it some thinking and waiting for more suggestions/patches.

About web spiders, it should not be a problem as long as the url -> language schema is consistent, like it is for any other page in the site. So the site will be indexed just fine. The only minor issue will be the front page for default language, which can be indexed with two different paths. On the other side, it is a nice feature to have al least for the home page.. So you'll have to balance pros and cons for enabling this but I wouldn't encourage nor discourage it...

jose reyero’s picture

Status: Active » Closed (won't fix)

This has been addressed in newer versions (5.x, 6.x) and Drupal 4.7 is not supported anymore. Please, consider upgrading

Biolin’s picture

Version: 4.7.x-1.x-dev » 5.x-2.6
Component: Code » Blocks

I am new with Drupal and I do have take care of a web site www.biolin.com and I use 3 languages for the moment on it (EN - FR - NL).

I did configure Drupal for Browser language detection and Internationalization.

Unfortunatly, when I use and different language on my browser or if I ask someone with another browser language to access the site ... the site home page remains in ENGLISH instead of switch to the page of the browser language of the visitor so for a french user it should be http://www.biolin.com/fr

so, right now, if a french visitor goes to the site he need to click on the language of is choice in the little menu on the left.

Have I done something wrong ? or did I missed something in the appropriate settings ?

Thank you in advance for your comments.