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

Localizations may not work on Linux #20

Open
Infocatcher opened this Issue Oct 11, 2013 · 4 comments

Comments

Projects
None yet
1 participant
@Infocatcher
Copy link
Owner

Infocatcher commented Oct 11, 2013

See https://forum.mozilla-russia.org/viewtopic.php?id=54385

So we should use

Components.classes["@mozilla.org/chrome/chrome-registry;1"]
    .getService(Components.interfaces.nsIXULChromeRegistry)
    .getSelectedLocale("global");

or

Components.classes["@mozilla.org/preferences-service;1"]
    .getService(Components.interfaces.nsIPrefBranch)
    .getComplexValue("general.useragent.locale", Components.interfaces.nsIPrefLocalizedString)
    .data;

But with getSelectedLocale() we need to have installed language pack to test localization (or change code each time).

@Infocatcher

This comment has been minimized.

Copy link
Owner Author

Infocatcher commented Oct 11, 2013

getComplexValue() seems to work fine on Linux, but doesn't work for default value on Windows:

Exception: Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIPrefBranch.getComplexValue]

getCharPref(): always works on Windows, but returns chrome://global/locale/intl.properties on Linux for default value.

getSelectedLocale(): seems to always works, but only if installed corresponding language pack for browser.

Also with intl.locale.matchOS = true general.useragent.locale isn't used at all.

@Infocatcher

This comment has been minimized.

Copy link
Owner Author

Infocatcher commented Oct 11, 2013

D'oh...

(function() {
    //var prefs = Services.prefs; 
    var prefs = Components.classes["@mozilla.org/preferences-service;1"]
        .getService(Components.interfaces.nsIPrefBranch);
    if(!prefs.getBoolPref("intl.locale.matchOS")) {
        var locale = prefs.getCharPref("general.useragent.locale");
        if(locale.substr(0, 9) != "chrome://")
            return locale;
    }
    return Components.classes["@mozilla.org/chrome/chrome-registry;1"]
        .getService(Components.interfaces.nsIXULChromeRegistry)
        .getSelectedLocale("global");
})().match(/^[a-z]*/)[0];
@Infocatcher

This comment has been minimized.

Copy link
Owner Author

Infocatcher commented Oct 11, 2013

Also for OS locale:

Components.classes["@mozilla.org/intl/nslocaleservice;1"]
    .getService(Components.interfaces.nsILocaleService)
    .getSystemLocale()
    .getCategory("NSILOCALE_COLLATE");

https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsILocaleService
https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsILocale

@Infocatcher

This comment has been minimized.

Copy link
Owner Author

Infocatcher commented Oct 25, 2013

Alternative way:

Services.urlFormatter.formatURL("%LOCALE%")

https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIURLFormatter
http://mxr.mozilla.org/mozilla-central/source/toolkit/components/urlformatter/nsURLFormatter.js#90

  _defaults: {
    LOCALE:           function() Cc["@mozilla.org/chrome/chrome-registry;1"].
                                 getService(Ci.nsIXULChromeRegistry).
                                 getSelectedLocale('global'),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.