Bug 1449505 - Migrate Preferences languages.js to use mozIntl.getLocaleDisplayNames. r?jaws draft
authorZibi Braniecki <zbraniecki@mozilla.com>
Sun, 01 Apr 2018 15:08:08 +0200
changeset 780068 3d8a6c0c92b3fce0e77648882c1cb95dc36f4e48
parent 780067 b19f2cddb206cdf764717725885f7d40dcf23903
child 780069 f47c4f5e0e57c94569e7cd9852b0f640beb1dc17
push id105952
push userbmo:gandalf@aviary.pl
push dateWed, 11 Apr 2018 05:43:29 +0000
reviewersjaws
bugs1449505
milestone61.0a1
Bug 1449505 - Migrate Preferences languages.js to use mozIntl.getLocaleDisplayNames. r?jaws MozReview-Commit-ID: BBFJXlxRAOy
browser/components/preferences/languages.js
browser/components/preferences/languages.xul
browser/locales/en-US/chrome/browser/preferences/preferences.properties
--- a/browser/components/preferences/languages.js
+++ b/browser/components/preferences/languages.js
@@ -46,70 +46,53 @@ var gLanguagesDialog = {
 
   _loadAvailableLanguages() {
     // This is a parser for: resource://gre/res/language.properties
     // The file is formatted like so:
     // ab[-cd].accept=true|false
     //  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) {
       this.name = aName;
       this.abcd = aABCD;
       this.isVisible = aIsVisible;
     }
 
     // 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))
         break;
 
       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();
   },
 
   _buildAvailableLanguageList() {
     var availableLanguagesPopup = document.getElementById("availableLanguagesPopup");
     while (availableLanguagesPopup.hasChildNodes())
       availableLanguagesPopup.firstChild.remove();
 
--- a/browser/components/preferences/languages.xul
+++ b/browser/components/preferences/languages.xul
@@ -32,18 +32,16 @@
 
   <keyset>
     <key key="&windowClose.key;" modifiers="accel" oncommand="Preferences.close(event)"/>
   </keyset>
 
   <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>
 
     <description>&languages.customize2.description;</description>
     <checkbox id="spoofEnglish"
               label="&languages.customize.spoofEnglish;"
               preference="privacy.spoof_english"
--- a/browser/locales/en-US/chrome/browser/preferences/preferences.properties
+++ b/browser/locales/en-US/chrome/browser/preferences/preferences.properties
@@ -70,22 +70,21 @@ mozfullDesc2=Blocks known trackers. Some
 
 #### Master Password
 
 pw_change2empty_in_fips_mode=You are currently in FIPS mode. FIPS requires a non-empty Master Password.
 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
 
 desktopFolderName=Desktop
 downloadsFolderName=Downloads
 chooseDownloadFolderTitle=Choose Download Folder: