Bug 1449505 - Migrate NarrateControls.jsm to use mozIntl.getLocaleDisplayNames. r?jfkthame draft
authorZibi Braniecki <zbraniecki@mozilla.com>
Sun, 01 Apr 2018 14:35:49 +0200
changeset 780082 bec5b0d71a3a9eb343e4b25d843e3a93e824253b
parent 780081 a6997da1d6c4cb3bb899ac5086761578fddafb35
child 780083 2c9adb9f14e2e8ae3e568c1ff64885ed76e6338a
push id105961
push userbmo:gandalf@aviary.pl
push dateWed, 11 Apr 2018 07:08:45 +0000
reviewersjfkthame
bugs1449505
milestone61.0a1
Bug 1449505 - Migrate NarrateControls.jsm to use mozIntl.getLocaleDisplayNames. r?jfkthame MozReview-Commit-ID: FN8jdXSuRky
toolkit/components/narrate/NarrateControls.jsm
--- a/toolkit/components/narrate/NarrateControls.jsm
+++ b/toolkit/components/narrate/NarrateControls.jsm
@@ -243,24 +243,22 @@ NarrateControls.prototype = {
         // language name or show the tag if none exists.
         // This is the ideal naming scheme so it is also the "default".
         return gStrings.formatStringFromName("voiceLabel",
           [voice.name, this._getLanguageName(voice.lang) || voice.lang], 2);
     }
   },
 
   _getLanguageName(lang) {
-    if (!this._langStrings) {
-      this._langStrings = Services.strings.createBundle(
-        "chrome://global/locale/languageNames.properties ");
-    }
+    try {
+      // This may throw if the lang doesn't match.
+      // XXX: Replace with Intl.Locale once bug 1433303 lands.
+      let langCode = lang.match(/^[a-z]{2,3}/)[0];
 
-    try {
-      // language tags will be lower case ascii between 2 and 3 characters long.
-      return this._langStrings.GetStringFromName(lang.match(/^[a-z]{2,3}/)[0]);
+      return Services.intl.getLanguageDisplayNames(undefined, [langCode]);
     } catch (e) {
       return "";
     }
   },
 
   _convertRate(rate) {
     // We need to convert a relative percentage value to a fraction rate value.
     // eg. -100 is half the speed, 100 is twice the speed in percentage,