зеркало из https://github.com/mozilla/gecko-dev.git
Bug 782924 - Allow locale specific preferences in distribution.ini; r=mixedpuppy
This commit is contained in:
Родитель
0b4dbfa17f
Коммит
94377b6e83
|
@ -346,11 +346,47 @@ DistributionCustomizer.prototype = {
|
|||
Cu.reportError(e);
|
||||
}
|
||||
|
||||
var usedPreferences = [];
|
||||
|
||||
if (sections["Preferences-" + this._locale]) {
|
||||
for (let key of enumerate(this._ini.getKeys("Preferences-" + this._locale))) {
|
||||
try {
|
||||
let value = this._ini.getString("Preferences-" + this._locale, key);
|
||||
if (value) {
|
||||
Preferences.set(key, parseValue(value));
|
||||
}
|
||||
usedPreferences.push(key);
|
||||
} catch (e) { /* ignore bad prefs and move on */ }
|
||||
}
|
||||
}
|
||||
|
||||
if (sections["Preferences-" + this._language]) {
|
||||
for (let key of enumerate(this._ini.getKeys("Preferences-" + this._language))) {
|
||||
if (usedPreferences.indexOf(key) > -1) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
let value = this._ini.getString("Preferences-" + this._language, key);
|
||||
if (value) {
|
||||
Preferences.set(key, parseValue(value));
|
||||
}
|
||||
usedPreferences.push(key);
|
||||
} catch (e) { /* ignore bad prefs and move on */ }
|
||||
}
|
||||
}
|
||||
|
||||
if (sections["Preferences"]) {
|
||||
for (let key of enumerate(this._ini.getKeys("Preferences"))) {
|
||||
if (usedPreferences.indexOf(key) > -1) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
let value = parseValue(this._ini.getString("Preferences", key));
|
||||
Preferences.set(key, value);
|
||||
let value = this._ini.getString("Preferences", key);
|
||||
if (value) {
|
||||
value = value.replace(/%LOCALE%/g, this._locale);
|
||||
value = value.replace(/%LANGUAGE%/g, this._language);
|
||||
Preferences.set(key, parseValue(value));
|
||||
}
|
||||
} catch (e) { /* ignore bad prefs and move on */ }
|
||||
}
|
||||
}
|
||||
|
@ -363,8 +399,9 @@ DistributionCustomizer.prototype = {
|
|||
if (sections["LocalizablePreferences-" + this._locale]) {
|
||||
for (let key of enumerate(this._ini.getKeys("LocalizablePreferences-" + this._locale))) {
|
||||
try {
|
||||
let value = parseValue(this._ini.getString("LocalizablePreferences-" + this._locale, key));
|
||||
if (value !== undefined) {
|
||||
let value = this._ini.getString("LocalizablePreferences-" + this._locale, key);
|
||||
if (value) {
|
||||
value = parseValue(value);
|
||||
localizedStr.data = "data:text/plain," + key + "=" + value;
|
||||
defaults._prefBranch.setComplexValue(key, Ci.nsIPrefLocalizedString, localizedStr);
|
||||
}
|
||||
|
@ -379,8 +416,9 @@ DistributionCustomizer.prototype = {
|
|||
continue;
|
||||
}
|
||||
try {
|
||||
let value = parseValue(this._ini.getString("LocalizablePreferences-" + this._language, key));
|
||||
if (value !== undefined) {
|
||||
let value = this._ini.getString("LocalizablePreferences-" + this._language, key);
|
||||
if (value) {
|
||||
value = parseValue(value);
|
||||
localizedStr.data = "data:text/plain," + key + "=" + value;
|
||||
defaults._prefBranch.setComplexValue(key, Ci.nsIPrefLocalizedString, localizedStr);
|
||||
}
|
||||
|
@ -395,13 +433,14 @@ DistributionCustomizer.prototype = {
|
|||
continue;
|
||||
}
|
||||
try {
|
||||
let value = parseValue(this._ini.getString("LocalizablePreferences", key));
|
||||
if (value !== undefined) {
|
||||
let value = this._ini.getString("LocalizablePreferences", key);
|
||||
if (value) {
|
||||
value = parseValue(value);
|
||||
value = value.replace(/%LOCALE%/g, this._locale);
|
||||
value = value.replace(/%LANGUAGE%/g, this._language);
|
||||
localizedStr.data = "data:text/plain," + key + "=" + value;
|
||||
defaults._prefBranch.setComplexValue(key, Ci.nsIPrefLocalizedString, localizedStr);
|
||||
}
|
||||
defaults._prefBranch.setComplexValue(key, Ci.nsIPrefLocalizedString, localizedStr);
|
||||
} catch (e) { /* ignore bad prefs and move on */ }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,28 @@ distribution.test.string.noquotes=Test String
|
|||
distribution.test.int=777
|
||||
distribution.test.bool.true=true
|
||||
distribution.test.bool.false=false
|
||||
distribution.test.empty=
|
||||
|
||||
distribution.test.pref.locale="%LOCALE%"
|
||||
distribution.test.pref.language.reset="Preference Set"
|
||||
distribution.test.pref.locale.reset="Preference Set"
|
||||
distribution.test.pref.locale.set="Preference Set"
|
||||
distribution.test.pref.language.set="Preference Set"
|
||||
|
||||
[Preferences-en]
|
||||
distribution.test.pref.language.en="en"
|
||||
distribution.test.pref.language.reset=
|
||||
distribution.test.pref.language.set="Language Set"
|
||||
distribution.test.pref.locale.set="Language Set"
|
||||
|
||||
[Preferences-en-US]
|
||||
distribution.test.pref.locale.en-US="en-US"
|
||||
distribution.test.pref.locale.reset=
|
||||
distribution.test.pref.locale.set="Locale Set"
|
||||
|
||||
|
||||
[Preferences-de]
|
||||
distribution.test.pref.language.de="de"
|
||||
|
||||
[LocalizablePreferences]
|
||||
distribution.test.locale="%LOCALE%"
|
||||
|
@ -33,4 +55,4 @@ distribution.test.locale.reset=
|
|||
distribution.test.locale.set="Locale Set"
|
||||
|
||||
[LocalizablePreferences-de]
|
||||
distribution.test.locale.de="de"
|
||||
distribution.test.language.de="de"
|
||||
|
|
|
@ -71,10 +71,30 @@ add_task(function* () {
|
|||
Assert.equal(Services.prefs.getIntPref("distribution.test.int"), 777);
|
||||
Assert.equal(Services.prefs.getBoolPref("distribution.test.bool.true"), true);
|
||||
Assert.equal(Services.prefs.getBoolPref("distribution.test.bool.false"), false);
|
||||
|
||||
Assert.throws(() => Services.prefs.getCharPref("distribution.test.empty"));
|
||||
Assert.throws(() => Services.prefs.getIntPref("distribution.test.empty"));
|
||||
Assert.throws(() => Services.prefs.getBoolPref("distribution.test.empty"));
|
||||
|
||||
Assert.equal(Services.prefs.getCharPref("distribution.test.pref.locale"), "en-US");
|
||||
Assert.equal(Services.prefs.getCharPref("distribution.test.pref.language.en"), "en");
|
||||
Assert.equal(Services.prefs.getCharPref("distribution.test.pref.locale.en-US"), "en-US");
|
||||
Assert.throws(() => Services.prefs.getCharPref("distribution.test.pref.language.de"));
|
||||
// This value was never set because of the empty language specific pref
|
||||
Assert.throws(() => Services.prefs.getCharPref("distribution.test.pref.language.reset"));
|
||||
// This value was never set because of the empty locale specific pref
|
||||
Assert.throws(() => Services.prefs.getCharPref("distribution.test.pref.locale.reset"));
|
||||
// This value was overridden by a locale specific setting
|
||||
Assert.equal(Services.prefs.getCharPref("distribution.test.pref.locale.set"), "Locale Set");
|
||||
// This value was overridden by a language specific setting
|
||||
Assert.equal(Services.prefs.getCharPref("distribution.test.pref.language.set"), "Language Set");
|
||||
// Language should not override locale
|
||||
Assert.notEqual(Services.prefs.getCharPref("distribution.test.pref.locale.set"), "Language Set");
|
||||
|
||||
Assert.equal(Services.prefs.getComplexValue("distribution.test.locale", Ci.nsIPrefLocalizedString).data, "en-US");
|
||||
Assert.equal(Services.prefs.getComplexValue("distribution.test.language.en", Ci.nsIPrefLocalizedString).data, "en");
|
||||
Assert.equal(Services.prefs.getComplexValue("distribution.test.locale.en-US", Ci.nsIPrefLocalizedString).data, "en-US");
|
||||
Assert.throws(() => Services.prefs.getComplexValue("distribution.test.locale.de", Ci.nsIPrefLocalizedString));
|
||||
Assert.throws(() => Services.prefs.getComplexValue("distribution.test.language.de", Ci.nsIPrefLocalizedString));
|
||||
// This value was never set because of the empty language specific pref
|
||||
Assert.throws(() => Services.prefs.getComplexValue("distribution.test.language.reset", Ci.nsIPrefLocalizedString));
|
||||
// This value was never set because of the empty locale specific pref
|
||||
|
|
Загрузка…
Ссылка в новой задаче