tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 47743cae5d026d1c6cf360fad0e969f0b9c1c479
parent 3ce9556dbe3fc124ade9c856c6ce68779f78ea3e
Author: Lorenz A <me@lorenzackermann.xyz>
Date:   Thu, 11 Dec 2025 07:02:51 +0000

Bug 2004235 - [devtools] Turn devtools/shared/l10n.js into an ES class. r=devtools-reviewers,bomsy

Differential Revision: https://phabricator.services.mozilla.com/D275640

Diffstat:
Mdevtools/shared/l10n.js | 93+++++++++++++++++++++++++++++++++++++++++--------------------------------------
1 file changed, 48 insertions(+), 45 deletions(-)

diff --git a/devtools/shared/l10n.js b/devtools/shared/l10n.js @@ -70,18 +70,19 @@ function getProperties(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, strict = false) { - this.stringBundleName = stringBundleName; - this.strict = strict; -} - -LocalizationHelper.prototype = { +class LocalizationHelper { + /** + * + * @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. + */ + constructor(stringBundleName, strict = false) { + this.stringBundleName = stringBundleName; + this.strict = strict; + } /** * L10N shortcut function. * @@ -100,7 +101,7 @@ LocalizationHelper.prototype = { console.error("No localization found for [" + name + "]"); return name; - }, + } /** * L10N shortcut function. @@ -111,7 +112,7 @@ LocalizationHelper.prototype = { */ getFormatStr(name, ...args) { return sprintf(this.getStr(name), ...args); - }, + } /** * L10N shortcut function for numeric arguments that need to be formatted. @@ -128,7 +129,7 @@ LocalizationHelper.prototype = { }); return this.getFormatStr(name, ...newArgs); - }, + } /** * Converts a number to a locale-aware string format and keeps a certain @@ -164,8 +165,8 @@ LocalizationHelper.prototype = { } return localized; - }, -}; + } +} function getPropertiesForNode(node) { const bundleEl = node.closest("[data-localization-bundle]"); @@ -228,37 +229,39 @@ function localizeMarkup(root) { * 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 => { - // Use strict = true because the MultiLocalizationHelper logic relies on try/catch - // around the underlying LocalizationHelper APIs. - return new LocalizationHelper(bundle, true); - }); +class MultiLocalizationHelper { + constructor(...stringBundleNames) { + const instances = stringBundleNames.map(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, - descriptor: Object.getOwnPropertyDescriptor( - LocalizationHelper.prototype, - name - ), - })) - .filter(({ descriptor }) => descriptor.value instanceof Function) - .forEach(method => { - this[method.name] = (...args) => { - for (const l10n of instances) { - try { - return method.descriptor.value.apply(l10n, args); - } catch (e) { - // Do nothing + // 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, + descriptor: Object.getOwnPropertyDescriptor( + LocalizationHelper.prototype, + name + ), + })) + .filter(({ descriptor }) => descriptor.value instanceof Function) + .forEach(method => { + this[method.name] = (...args) => { + for (const l10n of instances) { + try { + return method.descriptor.value.apply(l10n, args); + } catch (e) { + // Do nothing + } } - } - return null; - }; - }); + return null; + }; + }); + } } exports.LocalizationHelper = LocalizationHelper;