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.

Comments

account-deletion-needed’s picture

StatusFileSize
new669 bytes

Oops forgot to attach the patch ...

account-deletion-needed’s picture

StatusFileSize
new674 bytes

Patch updated to better regexp.

boaz_r’s picture

Status: Needs review » Reviewed & tested by the community

Hi,

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.

boaz_r’s picture

StatusFileSize
new985 bytes

and the patch of course...

damien tournoud’s picture

Status: Reviewed & tested by the community » Closed (duplicate)