Some countries (such as Switzerland which is officially German, French, Italian and Romansh) provide a browser language code of the format language-country, for example de-CH for the German language in Switzerland.
The problem is that in Internet Explorer the country code is lowercase whereas in all other browsers it's uppercase. For some reason this causes language_from_browser() to fail setting the correct language.
As a workaround I've provided a patch which removes the hyphen matching in the first parenthesis of the regexp. Thus, languages with country codes that previously retained their hyphen, now are stripped off the hyphen to the language code only.
I'm not sure if the country code is needed in certain multilingual setups and don't know enough about the language system in general. So consider this patch a dirty fix until someone with more knowledge can review this.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | language.inc_.diff | 985 bytes | boaz_r |
| #2 | language.inc_.patch | 674 bytes | account-deletion-needed |
| #1 | language.inc_.patch | 669 bytes | account-deletion-needed |
Comments
Comment #1
account-deletion-needed commentedOops forgot to attach the patch ...
Comment #2
account-deletion-needed commentedPatch updated to better regexp.
Comment #3
boaz_r commentedHi,
Bumped onto the same thing.
I'm not sure this matters, but I've updated the regexp to the following:
preg_match("!([a-z]+)[a-zA-Z-]*(;q=([0-9\\.]+))?!", trim($browser_accept[$i]), $found)
the difference is bolded.
AFAIK, the character class (for the CH, IT "suffix" of the language string) needs to be told to expect uppercase as well.
Oddly, I didn't need this fix for it to work in my test, but that's possibly due to php configuration(?).
I really wish this goes into main branch. I don't wanna patch my Drupal core.
Comment #4
boaz_r commentedand the patch of course...
Comment #5
damien tournoud commentedThis is a duplicate of #221712: locale_language_from_browser() doesn't parse language tags correctly, has a broken logic.