Bug 1449505 - Migrate NarrateControls.jsm to use mozIntl.getLocaleDisplayNames. r?jfkthame
MozReview-Commit-ID: FN8jdXSuRky
--- 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,