Commit 399d2ba8 authored by Igor Oliveira's avatar Igor Oliveira Committed by Arthur Edelstein
Browse files

Bug 26100: Migrate general.useragent.locale to intl.locale.requested

intl.locale.requested is the new way that Gecko handles locales.
See https://bugzilla.mozilla.org/show_bug.cgi?id=1414390
parent 8057989d
......@@ -67,8 +67,10 @@ var AboutTorListener = {
onPageLoad: function() {
// Arrange to update localized text and links.
bindPrefAndInit("general.useragent.locale", aNewVal => {
this.onLocaleChange(aNewVal);
bindPrefAndInit("intl.locale.requested", aNewVal => {
if (aNewVal !== null) {
this.onLocaleChange(aNewVal);
}
});
// Add message and event listeners.
......
......@@ -22,6 +22,6 @@
position="1"
label="&aboutTor.torbrowser_user_manual.label;"
accesskey="&aboutTor.torbrowser_user_manual.accesskey;"
oncommand="gBrowser.selectedTab = gBrowser.addTab('https://tb-manual.torproject.org/' + Services.prefs.getCharPref('general.useragent.locale'))" />
oncommand="gBrowser.selectedTab = gBrowser.addTab('https://tb-manual.torproject.org/' + Services.locale.getRequestedLocale())" />
</menupopup>
</overlay>
......@@ -5,6 +5,9 @@ let { utils: Cu } = Components;
let { getBoolPref, getIntPref, setBoolPref, setIntPref, getCharPref } =
Cu.import("resource://gre/modules/Services.jsm", {}).Services.prefs;
let { getLocale } =
Cu.import("resource://torbutton/modules/utils.js", {});
// Description elements have the follow names.
const descNames =
[, "desc_safest", "desc_safer", "desc_standard"];
......@@ -67,7 +70,7 @@ function torbutton_set_learn_more_links() {
let show_manual = window.opener.torbutton_show_torbrowser_manual();
let locale = ""
if (show_manual) {
locale = getCharPref('general.useragent.locale');
locale = getLocale();
}
let links = linkNames.map(name => document.getElementById(name));
links.forEach(link => {;
......
......@@ -10,7 +10,7 @@
let { LoadContextInfo } = Cu.import('resource://gre/modules/LoadContextInfo.jsm', {});
let { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
let { showDialog } = Cu.import("resource://torbutton/modules/utils.js", {});
let { unescapeTorString } = Cu.import("resource://torbutton/modules/utils.js", {});
let { getLocale, unescapeTorString } = Cu.import("resource://torbutton/modules/utils.js", {});
let SecurityPrefs = Cu.import("resource://torbutton/modules/security-prefs.js", {});
let { bindPrefAndInit, observe } = Cu.import("resource://torbutton/modules/utils.js", {});
......@@ -818,14 +818,14 @@ function torbutton_update_toolbutton()
// Bug 1506 P3: Support code for language+uagent spoofing
function torbutton_get_general_useragent_locale() {
try {
var locale = m_tb_prefs.getCharPref("general.useragent.locale");
const locale = getLocale();
if (/chrome:\/\//.test(locale)) {
return m_tb_prefs.getComplexValue("general.useragent.locale",
return m_tb_prefs.getComplexValue("intl.locale.requested",
Components.interfaces.nsIPrefLocalizedString).data;
}
return locale;
} catch(err) {
torbutton_log(4, "Error while getting general.useragent.locale:" + err);
torbutton_log(4, "Error while getting locale" + err);
return 'en-US';
}
}
......@@ -2380,7 +2380,7 @@ function torbutton_show_torbrowser_manual() {
// torbutton_show_torbrowser_manual() returns true.
function torbutton_init_user_manual_links() {
let menuitem = document.getElementById("torBrowserUserManual");
bindPrefAndInit("general.useragent.locale", val => {
bindPrefAndInit("intl.locale.requested", val => {
menuitem.hidden = !torbutton_show_torbrowser_manual();
torbutton_abouttor_message_handler.updateAllOpenPages();
});
......
......@@ -79,6 +79,12 @@ var getEnv = function (name) {
return env.exists(name) ? env.get(name) : undefined;
};
// __getLocale
// Reads the browser locale, the default locale is en-US.
var getLocale = function() {
return Services.locale.getRequestedLocale() || "en-US";
}
// ## Windows
// __dialogsByName__.
......@@ -200,5 +206,5 @@ var unescapeTorString = function(str) {
};
// Export utility functions for external use.
let EXPORTED_SYMBOLS = ["bindPref", "bindPrefAndInit", "getEnv", "getPrefValue",
"observe", "showDialog", "unescapeTorString"];
let EXPORTED_SYMBOLS = ["bindPref", "bindPrefAndInit", "getEnv", "getLocale",
"getPrefValue", "observe", "showDialog", "unescapeTorString"];
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment