Bug 1828668 - Properly handle zh-TW langpack and add test case r=gregtatum

Differential Revision: https://phabricator.services.mozilla.com/D177111
This commit is contained in:
Emily McMinn 2023-05-08 21:26:23 +00:00
parent 8cca6d7c0a
commit 55de180877
2 changed files with 18 additions and 2 deletions

View file

@ -52,12 +52,20 @@ async function negotiateLangPackForLanguageMismatch() {
* @type {LangPack | null}
*/
const langPack =
// First look for a langpack that matches the baseName.
// First look for a langpack that matches the baseName, which may include a script.
// e.g. system "fr-FR" matches langpack "fr-FR"
// system "en-GB" matches langpack "en-GB".
// system "zh-Hant-CN" matches langpack "zh-Hant-CN".
availableLangpacks.find(
({ target_locale }) => target_locale === localeInfo.systemLocale.baseName
) ||
// Next try matching language and region while excluding script
// e.g. system "zh-Hant-TW" matches langpack "zh-TW" but not "zh-CN".
availableLangpacks.find(
({ target_locale }) =>
target_locale ===
`${localeInfo.systemLocale.language}-${localeInfo.systemLocale.region}`
) ||
// Next look for langpacks that just match the language.
// e.g. system "fr-FR" matches langpack "fr".
// system "en-AU" matches langpack "en".

View file

@ -195,10 +195,18 @@ add_task(async function test_negotiateLangPacks() {
// Match with a script. zh-Hans-CN is the locale used with simplified
// Chinese scripts, while zh-CN uses the Latin script.
systemLocale: "zh-Hans-CN",
availableLangPacks: ["en", "en-US", "zh", "zh-CN", "zh-Hans-CN"],
availableLangPacks: ["en", "en-US", "zh", "zh-CN", "zh-TW", "zh-Hans-CN"],
expectedLangPack: "zh-Hans-CN",
expectedDisplayName: "Chinese (Hans, China)",
},
{
// Match excluding script but matching region. zh-Hant-TW should
// match zh-TW before zh-CN.
systemLocale: "zh-Hant-TW",
availableLangPacks: ["en", "zh", "zh-CN", "zh-TW"],
expectedLangPack: "zh-TW",
expectedDisplayName: "正體中文",
},
{
// No reasonable match could be found.
systemLocale: "tlh", // Klingon