Bug 1249630 - Add language support to distribution.js; r?mixedpuppy draft
authorMichael Kaply <mozilla@kaply.com>
Fri, 19 Feb 2016 09:26:55 -0600
changeset 332139 4aeb9c44e095764117117e6b9d1c05f881b75bb4
parent 332126 a87d6d52c1fcfffbd6f44537a9671973802cca13
child 514549 42ce43b47c80eafc1d19e51a7aac560f605d3c9e
push id11169
push usermozilla@kaply.com
push dateFri, 19 Feb 2016 15:34:05 +0000
reviewersmixedpuppy
bugs1249630
milestone47.0a1
Bug 1249630 - Add language support to distribution.js; r?mixedpuppy MozReview-Commit-ID: Cnk6qZ8uSfZ
browser/components/distribution.js
--- a/browser/components/distribution.js
+++ b/browser/components/distribution.js
@@ -65,16 +65,22 @@ DistributionCustomizer.prototype = {
     }
     catch (e) {
       locale = "en-US";
     }
     this.__defineGetter__("_locale", () => locale);
     return this._locale;
   },
 
+  get _language() {
+    let language = this._locale.split("-")[0];
+    this.__defineGetter__("_language", () => language);
+    return this._language;
+  },
+
   get _prefSvc() {
     let svc = Cc["@mozilla.org/preferences-service;1"].
               getService(Ci.nsIPrefService);
     this.__defineGetter__("_prefSvc", () => svc);
     return this._prefSvc;
   },
 
   get _prefs() {
@@ -107,16 +113,18 @@ DistributionCustomizer.prototype = {
         let [foo, itemIndex, iprop, ilocale] = m;
         itemIndex = parseInt(itemIndex);
 
         if (ilocale)
           continue;
 
         if (keys.indexOf(key + "." + this._locale) >= 0) {
           key += "." + this._locale;
+        } else if (keys.indexOf(key + "." + this._language) >= 0) {
+          key += "." + this._language;
         }
 
         if (!items[itemIndex])
           items[itemIndex] = {};
         items[itemIndex][iprop] = this._ini.getString(section, key);
 
         if (iprop == "type" && items[itemIndex]["type"] == "default")
           defaultIndex = itemIndex;
@@ -318,16 +326,18 @@ DistributionCustomizer.prototype = {
     defaults.setCharPref("distribution.version",
                          this._ini.getString("Global", "version"));
 
     let partnerAbout = Cc["@mozilla.org/supports-string;1"].
       createInstance(Ci.nsISupportsString);
     try {
       if (globalPrefs["about." + this._locale]) {
         partnerAbout.data = this._ini.getString("Global", "about." + this._locale);
+      } else if (globalPrefs["about." + this._language]) {
+        partnerAbout.data = this._ini.getString("Global", "about." + this._language);
       } else {
         partnerAbout.data = this._ini.getString("Global", "about");
       }
       defaults.setComplexValue("distribution.about",
                                Ci.nsISupportsString, partnerAbout);
     } catch (e) {
       /* ignore bad prefs due to bug 895473 and move on */
       Cu.reportError(e);
@@ -362,16 +372,27 @@ DistributionCustomizer.prototype = {
     let localizedStr = Cc["@mozilla.org/pref-localizedstring;1"].
       createInstance(Ci.nsIPrefLocalizedString);
 
     if (sections["LocalizablePreferences"]) {
       for (let key of enumerate(this._ini.getKeys("LocalizablePreferences"))) {
         try {
           let value = eval(this._ini.getString("LocalizablePreferences", key));
           value = value.replace(/%LOCALE%/g, this._locale);
+          value = value.replace(/%LANGUAGE%/g, this._language);
+          localizedStr.data = "data:text/plain," + key + "=" + value;
+          defaults.setComplexValue(key, Ci.nsIPrefLocalizedString, localizedStr);
+        } catch (e) { /* ignore bad prefs and move on */ }
+      }
+    }
+
+    if (sections["LocalizablePreferences-" + this._language]) {
+      for (let key of enumerate(this._ini.getKeys("LocalizablePreferences-" + this._language))) {
+        try {
+          let value = eval(this._ini.getString("LocalizablePreferences-" + this._language, key));
           localizedStr.data = "data:text/plain," + key + "=" + value;
           defaults.setComplexValue(key, Ci.nsIPrefLocalizedString, localizedStr);
         } catch (e) { /* ignore bad prefs and move on */ }
       }
     }
 
     if (sections["LocalizablePreferences-" + this._locale]) {
       for (let key of enumerate(this._ini.getKeys("LocalizablePreferences-" + this._locale))) {