Bug 1464132 - devtools l10n use console.error if localized string is unavailable r=jlast
authorJulian Descottes <jdescottes@mozilla.com>
Thu, 16 May 2019 15:20:03 +0000
changeset 474200 09549fc20d2358a00cac6e9d6ec92e5031fe7e7b
parent 474199 1177f0af9ec0c7500ca5419a88de6b62cc07caf4
child 474201 9383ea5938fe62e6d29fb9ebb143b304b9070529
push id36027
push usershindli@mozilla.com
push dateFri, 17 May 2019 16:24:38 +0000
treeherdermozilla-central@c94c54aff466 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlast
bugs1464132
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1464132 - devtools l10n use console.error if localized string is unavailable r=jlast Throwing errors can lead to blank panels when we uplift strings to beta and language packs have not been regenerated yet. Try at: https://treeherder.mozilla.org/#/jobs?repo=try&revision=1520df8aa12a84b5c50b205ffda49a1e86e545c9 Differential Revision: https://phabricator.services.mozilla.com/D31455
devtools/shared/l10n.js
--- a/devtools/shared/l10n.js
+++ b/devtools/shared/l10n.js
@@ -85,35 +85,43 @@ function getProperties(url) {
   return propertiesMap[url];
 }
 
 /**
  * Localization convenience methods.
  *
  * @param string stringBundleName
  *        The desired string bundle's name.
+ * @param boolean strict
+ *        (legacy) pass true to force the helper to throw if the l10n id cannot be found.
  */
-function LocalizationHelper(stringBundleName) {
+function LocalizationHelper(stringBundleName, strict = false) {
   this.stringBundleName = stringBundleName;
+  this.strict = strict;
 }
 
 LocalizationHelper.prototype = {
   /**
    * L10N shortcut function.
    *
    * @param string name
    * @return string
    */
   getStr: function(name) {
     const properties = getProperties(this.stringBundleName);
     if (name in properties) {
       return properties[name];
     }
 
-    throw new Error("No localization found for [" + name + "]");
+    if (this.strict) {
+      throw new Error("No localization found for [" + name + "]");
+    }
+
+    console.error("No localization found for [" + name + "]");
+    return name;
   },
 
   /**
    * L10N shortcut function.
    *
    * @param string name
    * @param array args
    * @return string
@@ -236,17 +244,19 @@ function localizeMarkup(root) {
 const sharedL10N = new LocalizationHelper("devtools/shared/locales/shared.properties");
 
 /**
  * A helper for having the same interface as LocalizationHelper, but for more
  * than one file. Useful for abstracting l10n string locations.
  */
 function MultiLocalizationHelper(...stringBundleNames) {
   const instances = stringBundleNames.map(bundle => {
-    return new LocalizationHelper(bundle);
+    // Use strict = true because the MultiLocalizationHelper logic relies on try/catch
+    // around the underlying LocalizationHelper APIs.
+    return new LocalizationHelper(bundle, true);
   });
 
   // Get all function members of the LocalizationHelper class, making sure we're
   // not executing any potential getters while doing so, and wrap all the
   // methods we've found to work on all given string bundles.
   Object.getOwnPropertyNames(LocalizationHelper.prototype)
     .map(name => ({
       name: name,