Bug 1449505 - Migrate Preferences translation.js to use mozIntl.getLocaleDisplayNames. r?jaws
MozReview-Commit-ID: 3qjW0iQ9poi
--- a/browser/components/preferences/translation.js
+++ b/browser/components/preferences/translation.js
@@ -3,19 +3,16 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm");
-XPCOMUtils.defineLazyGetter(this, "gLangBundle", () =>
- Services.strings.createBundle("chrome://global/locale/languageNames.properties"));
-
const kPermissionType = "translate";
const kLanguagesPref = "browser.translation.neverForLanguages";
function Tree(aId, aData) {
this._data = aData;
this._tree = document.getElementById(aId);
this._tree.view = this;
}
@@ -71,19 +68,19 @@ Tree.prototype = {
return "";
},
getCellProperties(row, column) {
return "";
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsITreeView])
};
-function Lang(aCode) {
+function Lang(aCode, label) {
this.langCode = aCode;
- this._label = gLangBundle.GetStringFromName(aCode);
+ this._label = label;
}
Lang.prototype = {
toString() {
return this._label;
}
};
@@ -118,17 +115,19 @@ var gTranslationExceptions = {
},
// Get the list of languages we don't translate as an array.
getLanguageExceptions() {
let langs = Services.prefs.getCharPref(kLanguagesPref);
if (!langs)
return [];
- let result = langs.split(",").map(code => new Lang(code));
+ let langArr = langs.split(",");
+ let displayNames = Services.intl.getLanguageDisplayNames(undefined, langArr);
+ let result = langArr.map((lang, i) => new Lang(lang, displayNames[i]));
result.sort();
return result;
},
observe(aSubject, aTopic, aData) {
if (aTopic == "perm-changed") {
if (aData == "cleared") {