tor-browser

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

commit fecb7d40d1af2a27478fdd341b356f76efd6c244
parent 3c2d0ad5612be9316eb1d94d951bb6316357be76
Author: Julian Descottes <jdescottes@mozilla.com>
Date:   Tue,  4 Nov 2025 17:35:12 +0000

Bug 1997708 - [devtools] Fix PluralForm with legacy gecko locale ja-JP-mac r=nchevobbe,devtools-reviewers

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

Diffstat:
Mdevtools/shared/plural-form.js | 11+++++++++--
Adevtools/shared/tests/xpcshell/test_pluralForm-japanese.js | 28++++++++++++++++++++++++++++
Mdevtools/shared/tests/xpcshell/xpcshell.toml | 2++
3 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/devtools/shared/plural-form.js b/devtools/shared/plural-form.js @@ -78,8 +78,15 @@ const PluralForm = { */ getPluralRule() { - const appLocales = Services.locale.appLocalesAsLangTags; - const locale = new Intl.Locale(appLocales[0]); + let appLocale = Services.locale.appLocalesAsLangTags[0]; + + // See searchfox.org/firefox-main/rev/f6385e6644d5d4343d33b692810275c434122199/intl/docs/locale.rst#463-471 + // Swap ja-JP-mac (legacy locale in gecko, but invalid) with the valid ja-JP-macos + if (appLocale === "ja-JP-mac") { + appLocale = "ja-JP-macos"; + } + + const locale = new Intl.Locale(appLocale); switch (locale.language) { case "bo": case "id": diff --git a/devtools/shared/tests/xpcshell/test_pluralForm-japanese.js b/devtools/shared/tests/xpcshell/test_pluralForm-japanese.js @@ -0,0 +1,28 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * This unit test makes sure the plural form for Japanese works. + * Japanese uses a legacy locale on gecko ja-JP-mac, which is not a valid locale + * for Intl.Locale, so make sure PluralForm doesn't throw for this locale. + * See Bug 1997708. + */ + +const { PluralForm } = require("resource://devtools/shared/plural-form.js"); + +function run_test() { + const origAvLocales = Services.locale.availableLocales; + registerCleanupFunction(() => { + Services.locale.availableLocales = origAvLocales; + }); + + Services.locale.availableLocales = ["ja-JP-mac", "en-US"]; + Services.locale.requestedLocales = ["ja-JP-mac"]; + PluralForm.init(); + + // Japanese has 1 plural form + Assert.equal(1, PluralForm.numForms()); +} diff --git a/devtools/shared/tests/xpcshell/xpcshell.toml b/devtools/shared/tests/xpcshell/xpcshell.toml @@ -61,6 +61,8 @@ skip-if = [ ["test_pluralForm-irish.js"] +["test_pluralForm-japanese.js"] + ["test_prettifyCSS.js"] skip-if = [ "os == 'android' && os_version == '14' && processor == 'x86_64'",