I have spent lots of time trying to find a way to get the locale of Firefox extension within the extension's Javascript code. The closes I am general.useragent.locale, which I think holds the preferred localization, but Firefox's user language can be totally different.
Any idea?
When trying to query XUL packages, have a look at nsIXULChromeRegistry.getSelectedLocale(package)
.
Sample (querying the locale for the global/toolkit package):
Components.classes["@mozilla.org/chrome/chrome-registry;1"]
.getService(Components.interfaces.nsIXULChromeRegistry)
.getSelectedLocale('global'); // e.g "en-US"
SDK add-ons could use the following to determine their own locale, although it should be noted that this API is marked "unstable".
require("sdk/l10n/core").locale
SDK add-ons may still use nsIXULChromeRegistry.getSelectedLocale(package)
to query other add-ons or the browser via the chrome
module.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.