Closed Infocatcher closed 2 years ago
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.
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];
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
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'),
See https://forum.mozilla-russia.org/viewtopic.php?id=54385
So we should use
or
But with
getSelectedLocale()
we need to have installed language pack to test localization (or change code each time).