Bug 1374552 - Fix i18n.getUILanguage so it does not replace dashes with underscores. r=mixedpuppy, a=gchang
authorBob Silverberg <bsilverberg@mozilla.com>
Fri, 11 Aug 2017 09:45:35 -0400
changeset 423953 cb905f9be690fd0dc9017a32951416eb85277c1e
parent 423952 a09fc917c9b91fd42602f9589896c40f0267dfb5
child 423954 90926a141c6dad8fa2041c7410f26ca0a1c88a25
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy, gchang
bugs1374552
milestone56.0
Bug 1374552 - Fix i18n.getUILanguage so it does not replace dashes with underscores. r=mixedpuppy, a=gchang When we implemented this API we converted dashes in the language code to underscores because that is what Chrome did. Chrome no longer does this, so we need to remove the code that does the replacing. MozReview-Commit-ID: DuOQ218zXby
toolkit/components/extensions/ExtensionCommon.jsm
toolkit/components/extensions/test/xpcshell/test_ext_i18n.js
toolkit/components/extensions/test/xpcshell/test_ext_i18n_css.js
--- a/toolkit/components/extensions/ExtensionCommon.jsm
+++ b/toolkit/components/extensions/ExtensionCommon.jsm
@@ -1347,19 +1347,17 @@ LocaleData.prototype = {
 
   get acceptLanguages() {
     let result = Preferences.get("intl.accept_languages", "", Ci.nsIPrefLocalizedString);
     return result.split(/\s*,\s*/g);
   },
 
 
   get uiLocale() {
-    // Return the browser locale, but convert it to a Chrome-style
-    // locale code.
-    return Services.locale.getAppLocaleAsBCP47().replace(/-/g, "_");
+    return Services.locale.getAppLocaleAsBCP47();
   },
 };
 
 defineLazyGetter(LocaleData.prototype, "availableLocales", function() {
   return new Set([this.BUILTIN, this.selectedLocale, this.defaultLocale]
                  .filter(locale => this.messages.has(locale)));
 });
 
--- a/toolkit/components/extensions/test/xpcshell/test_ext_i18n.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_i18n.js
@@ -365,17 +365,17 @@ add_task(async function test_get_ui_lang
     },
   });
 
   let contentPage = await ExtensionTestUtils.loadContentPage(`${BASE_URL}/file_sample.html`);
 
   await extension.startup();
   await extension.awaitMessage("content-loaded");
 
-  extension.sendMessage(["expect-results", "en_US"]);
+  extension.sendMessage(["expect-results", "en-US"]);
 
   await extension.awaitMessage("background-done");
   await extension.awaitMessage("content-done");
 
   // We don't currently have a good way to mock this.
   if (false) {
     Preferences.set("general.useragent.locale", "he");
 
--- a/toolkit/components/extensions/test/xpcshell/test_ext_i18n_css.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_i18n_css.js
@@ -110,17 +110,17 @@ async function test_i18n_css(options = {
 
   equal(maxWidth, "42px", "stylesheet correctly applied");
 
   await contentPage.close();
 
   cssURL = cssURL.replace(/foo.css$/, "locale.css");
 
   css = await fetch(cssURL);
-  equal(css, '* { content: "en_US ltr rtl left right" }', "CSS file localized in mochitest scope");
+  equal(css, '* { content: "en-US ltr rtl left right" }', "CSS file localized in mochitest scope");
 
   // We don't currently have a good way to mock this.
   if (false) {
     const LOCALE = "general.useragent.locale";
     const DIR = "intl.uidirection";
     const DIR_LEGACY = "intl.uidirection.en"; // Needed for Android until bug 1215247 is resolved
 
     // We don't wind up actually switching the chrome registry locale, since we