Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with browser codes selecting user interface language #4

Open
syseyes opened this issue Jun 22, 2016 · 2 comments
Open

Problem with browser codes selecting user interface language #4

syseyes opened this issue Jun 22, 2016 · 2 comments

Comments

@syseyes
Copy link
Contributor

syseyes commented Jun 22, 2016

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

@syseyes
Copy link
Contributor Author

syseyes commented Jun 22, 2016

I tried to create a pull request on github to solve that problem. Is my first time on Gihub so I dont know if I have done right or violated any netetiquete.

Bye

@zploskey
Copy link
Contributor

This change (merged in 1c7b373, pull request #5 ) breaks the case where the browser sends a 4 character locale code first and the site uses a 4 character locale code for translations. It sets $this->locale_code to the two character version, and then fails to find the translations which use the 4 character code. This results in nothing but dates being translated by Omeka. I would think that this would be a very common occurrence. Reverting this change fixes translations for our site in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants