2011年4月13日

Language code issue in Drupal 7.0

Because of IANA standard, Drupal 7.0 follow that standard for language/locale handling for Chinese.  However, most of the web browser use other language code format.  Below is the list:
IANA stanardard:
  1. Traditional Chinese: zh-hant
  2. Simplified Chinese: zh-hans
Web browser language code:
  1. Traditional Chinese: (e.g.) zh-tw, zh-hk
  2. Simplified Chinese: (e.g.) zh-cn, zh-sg
As a result, Drupal 7 cannot handle correctly in Browser Language Detection.  Drupal 7 will only return default language like English.  To solve this issue, there is a patch: In include/locale.inc #113
if (preg_match("!([a-z-]+)(;q=([0-9\\.]+))?!", trim($langpart), $found)) {

  // added 2 lines for browser detection for HK and TW:

  if ($found[1] == "zh-tw"||$found[1] == "zh-hk"||$found[1] == "zh"||$found[1] == "zh-") { $found[1] = "zh-hant";}

  if ($found[1] == "zh-cn"||$found[1] == "zh-sg") { $found[1] = "zh-hans";}


  $browser_langs[$found[1]] = (isset($found[3]) ? (float) $found[3] : 1.0);

}  

沒有留言:

發佈留言