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 780065 7f12a0782eff24147428c0acedb4b73f5bcc8f09
parent 780064 e3cd732dedfa11a62959c33e83e0a883906e8c3d
child 780066 94a48ae4635d4c245e7db6853932bb1fefb510cf
push id105952
push userbmo:gandalf@aviary.pl
push dateWed, 11 Apr 2018 05:43:29 +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,