Bug 1449505 - Migrate Preferences translation.js to use mozIntl.getLocaleDisplayNames. r?jaws draft
authorZibi Braniecki <zbraniecki@mozilla.com>
Sun, 01 Apr 2018 14:51:31 +0200
changeset 780066 94a48ae4635d4c245e7db6853932bb1fefb510cf
parent 780065 7f12a0782eff24147428c0acedb4b73f5bcc8f09
child 780067 b19f2cddb206cdf764717725885f7d40dcf23903
push id105952
push userbmo:gandalf@aviary.pl
push dateWed, 11 Apr 2018 05:43:29 +0000
reviewersjaws
bugs1449505
milestone61.0a1
Bug 1449505 - Migrate Preferences translation.js to use mozIntl.getLocaleDisplayNames. r?jaws MozReview-Commit-ID: 3qjW0iQ9poi
browser/components/preferences/translation.js
--- 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") {