Bug 1449505 - Migrate Preferences languages.js to use mozIntl.getLocaleDisplayNames. r=jaws

MozReview-Commit-ID: BBFJXlxRAOy

--HG--
extra : rebase_source : a0215933200ca5ef3c3a05ecffec2f3445f41c57
This commit is contained in:
Zibi Braniecki 2018-04-01 15:08:08 +02:00
Родитель 958538de36
Коммит 1312e353df
3 изменённых файлов: 23 добавлений и 43 удалений

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

@ -51,8 +51,6 @@ var gLanguagesDialog = {
// ab = language
// cd = region
var bundleAccepted = document.getElementById("bundleAccepted");
var bundleRegions = document.getElementById("bundleRegions");
var bundleLanguages = document.getElementById("bundleLanguages");
var bundlePreferences = document.getElementById("bundlePreferences");
function LanguageInfo(aName, aABCD, aIsVisible) {
@ -63,6 +61,9 @@ var gLanguagesDialog = {
// 1) Read the available languages out of language.properties
var strings = bundleAccepted.strings;
let localeCodes = [];
let localeValues = [];
while (strings.hasMoreElements()) {
var currString = strings.getNext();
if (!(currString instanceof Ci.nsIPropertyElement))
@ -70,41 +71,23 @@ var gLanguagesDialog = {
var property = currString.key.split("."); // ab[-cd].accept
if (property[1] == "accept") {
var abCD = property[0];
var abCDPairs = abCD.split("-"); // ab[-cd]
var useABCDFormat = abCDPairs.length > 1;
var ab = useABCDFormat ? abCDPairs[0] : abCD;
var cd = useABCDFormat ? abCDPairs[1] : "";
if (ab) {
var language = "";
try {
language = bundleLanguages.getString(ab);
} catch (e) { continue; }
var region = "";
if (useABCDFormat) {
try {
region = bundleRegions.getString(cd);
} catch (e) { continue; }
}
var name = "";
if (useABCDFormat)
name = bundlePreferences.getFormattedString("languageRegionCodeFormat",
[language, region, abCD]);
else
name = bundlePreferences.getFormattedString("languageCodeFormat",
[language, abCD]);
if (name && abCD) {
var isVisible = currString.value == "true" &&
(!(abCD in this._acceptLanguages) || !this._acceptLanguages[abCD]);
var li = new LanguageInfo(name, abCD, isVisible);
this._availableLanguagesList.push(li);
}
}
localeCodes.push(property[0]);
localeValues.push(currString.value);
}
}
let localeNames = Services.intl.getLocaleDisplayNames(undefined, localeCodes);
for (let i in localeCodes) {
let isVisible = localeValues[i] == "true" &&
(!(localeCodes[i] in this._acceptLanguages) || !this._acceptLanguages[localeCodes[i]]);
let name = bundlePreferences.getFormattedString("languageCodeFormat",
[localeNames[i], localeCodes[i]]);
let li = new LanguageInfo(name, localeCodes[i], isVisible);
this._availableLanguagesList.push(li);
}
this._buildAvailableLanguageList();
},

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

@ -37,8 +37,6 @@
<vbox id="LanguagesDialogPane" class="prefpane largeDialogContainer">
<stringbundleset id="languageSet">
<stringbundle id="bundleRegions" src="chrome://global/locale/regionNames.properties"/>
<stringbundle id="bundleLanguages" src="chrome://global/locale/languageNames.properties"/>
<stringbundle id="bundlePreferences" src="chrome://browser/locale/preferences/preferences.properties"/>
<stringbundle id="bundleAccepted" src="resource://gre/res/language.properties"/>
</stringbundleset>

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

@ -75,12 +75,11 @@ pw_change_failed_title=Password Change Failed
#### Fonts
# LOCALIZATION NOTE: Next two strings are for language name representations with
# and without the region.
# e.g. languageRegionCodeFormat : "French/Canada [fr-ca]" languageCodeFormat : "French [fr]"
# %1$S = language name, %2$S = region name, %3$S = language-region code
languageRegionCodeFormat=%1$S/%2$S [%3$S]
# %1$S = language name, %2$S = language-region code
# LOCALIZATION NOTE: The string represents a localized locale name
# followed by the BCP47 locale code.
#
# Example: "French (Canada) [fr-ca]"
# %1$S = locale name, %2$S = locale code
languageCodeFormat=%1$S [%2$S]
#### Downloads