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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Julian Descottes 2019-05-16 15:20:03 +00:00
Родитель 987553489a
Коммит 824f4a9e82
1 изменённых файлов: 13 добавлений и 3 удалений

Просмотреть файл

@ -90,9 +90,12 @@ function getProperties(url) {
*
* @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 = {
@ -108,7 +111,12 @@ LocalizationHelper.prototype = {
return properties[name];
}
if (this.strict) {
throw new Error("No localization found for [" + name + "]");
}
console.error("No localization found for [" + name + "]");
return name;
},
/**
@ -241,7 +249,9 @@ const sharedL10N = new LocalizationHelper("devtools/shared/locales/shared.proper
*/
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