Bug 1441016 - Migrate to intl.locale.requested.locale list from general.useragent.locale. r=frg

Also port the relevant parts of the following bugs to SeaMonkey:
* Bug 1346616 - Migrate callsites that are retrieving requested locale from pref, to use LocaleService::GetRequestedLocales
* Bug 1414390 - Add intl.locale.requested locale list to replace general.useragent.locale
This commit is contained in:
Ian Neal 2020-04-25 17:52:05 +01:00
Родитель f940ebc228
Коммит 262fbf1035
4 изменённых файлов: 45 добавлений и 36 удалений

Просмотреть файл

@ -412,7 +412,7 @@ SuiteGlue.prototype = {
* level.
*/
_migrateUI() {
const UI_VERSION = 9;
const UI_VERSION = 10;
// If the pref is not set this is a new or pre SeaMonkey 2.49 profile.
// We can't tell so we just run migration with version 0.
@ -593,6 +593,31 @@ SuiteGlue.prototype = {
Services.prefs.clearUserPref("browser.tabs.opentabfor.doubleclick");
}
// Migrate the old requested locales prefs to use the new model
if (currentUIVersion < 10) {
const SELECTED_LOCALE_PREF = "general.useragent.locale";
const MATCHOS_LOCALE_PREF = "intl.locale.matchOS";
if (Services.prefs.prefHasUserValue(MATCHOS_LOCALE_PREF) ||
Services.prefs.prefHasUserValue(SELECTED_LOCALE_PREF)) {
if (Services.prefs.getBoolPref(MATCHOS_LOCALE_PREF, false)) {
Services.locale.setRequestedLocales([]);
} else {
let locale = Services.prefs.getComplexValue(SELECTED_LOCALE_PREF,
Ci.nsIPrefLocalizedString);
if (locale) {
try {
Services.locale.setRequestedLocales([locale.data]);
} catch (e) {
/* Don't panic if the value is not a valid locale code. */
}
}
}
Services.prefs.clearUserPref(SELECTED_LOCALE_PREF);
Services.prefs.clearUserPref(MATCHOS_LOCALE_PREF);
}
}
// Update the migration version.
Services.prefs.setIntPref("suite.migration.version", UI_VERSION);
},

Просмотреть файл

@ -18,7 +18,6 @@ function Startup()
*/
function SwitchLocales_Load() {
var menulist = document.getElementById("switchLocales");
var pref = document.getElementById("general.useragent.locale");
var cr = Cc["@mozilla.org/chrome/chrome-registry;1"]
.getService(Ci.nsIToolkitChromeRegistry);
@ -26,6 +25,8 @@ function SwitchLocales_Load() {
var langNames = document.getElementById("languageNamesBundle");
var regNames = document.getElementById("regionNamesBundle");
var matched = false;
var currentLocale = Services.locale.getRequestedLocale() || undefined;
var locales = cr.getLocalesForPackage("global");
while (locales.hasMore()) {
@ -49,40 +50,27 @@ function SwitchLocales_Load() {
displayName = locale;
}
menulist.appendItem(displayName, locale);
var item = menulist.appendItem(displayName, locale);
if (!matched && currentLocale && currentLocale == locale) {
matched = true;
menulist.selectedItem = item;
}
}
// If somehow we have not found the current locale, select the first in list.
if (!matched) {
menulist.selectedIndex = 1;
}
pref.setElementValue(menulist);
}
/**
* determine the appropriate value to select
* go through element value, pref value and pref default value and use the first one available
* else fall back to the first available selection
* Determine the appropriate value to set and set it.
*/
function SelectLocale(aElement)
{
var matchItems;
var pref = document.getElementById(aElement.getAttribute("preference"));
if (pref.value) {
matchItems = aElement.getElementsByAttribute("value", pref.value);
// If the pref matches an entry that actually is in the list, use it.
if (matchItems.length)
return pref.value;
function SelectLocale(aElement) {
var locale = aElement.value;
var currentLocale = Services.locale.getRequestedLocale() || undefined;
if (!currentLocale || (currentLocale && currentLocale != locale)) {
Services.locale.setRequestedLocales([locale]);
}
if (pref.defaultValue) {
matchItems = aElement.getElementsByAttribute("value", pref.defaultValue);
// If the pref's default matches an entry that actually is in the list, use it.
if (matchItems.length)
return pref.defaultValue;
}
// If prefs can't point us to a valid value and something is set, leave that.
if (aElement.value)
return aElement.value;
// If somehow we still have no value, return the first value in the list
return aElement.firstChild.firstChild.getAttribute("value");
}
/**

Просмотреть файл

@ -27,9 +27,6 @@
<preference id="browser.toolbars.grippyhidden"
name="browser.toolbars.grippyhidden"
type="bool"/>
<preference id="general.useragent.locale"
name="general.useragent.locale"
type="string"/>
<preference id="intl.regional_prefs.use_os_locales"
name="intl.regional_prefs.use_os_locales"
type="bool"/>
@ -83,8 +80,7 @@
<description>&selectLocale.label;</description>
<menulist id="switchLocales"
preference="general.useragent.locale"
onsyncfrompreference="return document.getElementById('appearance_pane').SelectLocale(this);"/>
onselect="SelectLocale(this);"/>
</groupbox>

Просмотреть файл

@ -4,5 +4,5 @@
#filter substitution
pref("general.useragent.locale", "@AB_CD@");
pref("intl.locale.requested", "@AB_CD@");
pref("spellchecker.dictionary", "@AB_CD@");