Skip to content

Problem with browser codes selecting user interface language #4

@syseyes

Description

@syseyes

Hello,
I am trying your plugin in your environement, and I think I have found a bug in the language selection when the browser send language preferences.
Our aplications are multiligual. We use mainly two languages:
es: Spanish
ca_ES: Catalan (Catalan language, Territorial settings
I have discover that language selection from the browser fails with the ca_ES character code.

I believe the root cause come from that the browser send the language code without the territorial setting. The browser sends: " Accept-Language:ca,en;q=0.8,es;q=0.6"
and the script /plugins/MultilanguagePlugin.php fails to associate the right locale page.

I suspect the the failing code is these

 if (! $userPrefLanguageCode) {
            $codes = unserialize( get_option('multilanguage_language_codes') );
            //dump the site's default code to the end as a fallback
            $codes[] = $defaultCode;
            $browserCodes = array_keys(Zend_Locale::getBrowser());
            foreach ($browserCodes as $browserCode) {
                if (in_array($browserCode, $codes)) { //Fails comparing two caracter with 5 characer code**
                    $this->locale_code = $browserCode;
                    break;
                }
            }

I solved my case getting only the to first characters of the multilanguage_language_codes in order two compare

 if (! $userPrefLanguageCode) {
            $codes = unserialize( get_option('multilanguage_language_codes') );
            //dump the site's default code to the end as a fallback
            $codes[] = $defaultCode;

 //Reduce to two character code in order two compare
            for ($temp = 0; $temp < count($codes); $temp++) {
                $codes[$temp]=substr($codes[$temp], 0, 2);
            }

Thank you for your work.

Joan

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions