Problem:

In some Browser (IE, Safari, Opera) the browser sends something like "de-ch". For browser fallback we use the function "language_from_browser" to determine which language should be used. But the browser switch always back to the default language. In my environment it is "en". In firefox the problem does not appears. So I look at the code and here is the solution:

In the file "/includes/language.inc" on line 87:
$browser_langs[$found[1]] = (isset($found[3]) ? (float) $found[3] : 1.0);

The output is with no modification:

print_r($browser_langs);
Array ( [de-ch] => 1 [de-] => 1 )

But this can't be found, because i have only "de" installed and not "de-".

Solution

When you insure that the key is always without any "-" at the end, then it works. So change the line 87 to:
$browser_langs[trim($found[1], '-')] = (isset($found[3]) ? (float) $found[3] : 1.0);

The output is with modification:

print_r($browser_langs);
Array ( [de-ch] => 1 [de] => 1 )

Notice

I use the negotation mode "Path prefix with language fallback" and i have three langs active "de", "en" and "fr". ("en" is the default)

Comments

customweb’s picture

Version: 6.16 » 6.2
Component: base system » language system

Does someone implement this solution to the language system?

damien tournoud’s picture

Status: Active » Closed (duplicate)

Your original bug report doesn't make a lot of sense to me, but this seems to be a duplicate of #221712: locale_language_from_browser() doesn't parse language tags correctly, has a broken logic.