Merge pull request #17273 from Snuffleupagus/L10n-lowercase-locales

Re-factor the `L10n`-implementations to use lowercase language-codes internally
This commit is contained in:
Jonas Jenwald 2023-11-14 15:59:13 +01:00 committed by GitHub
commit 5099dc4699
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 21 deletions

View File

@ -896,10 +896,11 @@ gulp.task("locale", function () {
locales.push(locale); locales.push(locale);
if (checkFile(dirPath + "/viewer.ftl")) { if (checkFile(dirPath + "/viewer.ftl")) {
viewerOutput[locale] = `${locale}/viewer.ftl`; // The L10n-implementations, in the viewer, use lowercase language-codes
// internally.
viewerOutput[locale.toLowerCase()] = `${locale}/viewer.ftl`;
} }
} }
const glob = locales.length === 1 ? locales[0] : `{${locales.join(",")}}`; const glob = locales.length === 1 ? locales[0] : `{${locales.join(",")}}`;
return merge([ return merge([

View File

@ -48,7 +48,7 @@ class GenericExternalServices extends DefaultExternalServices {
} }
static async createL10n() { static async createL10n() {
return new GenericL10n(AppOptions.get("locale") || "en-US"); return new GenericL10n(AppOptions.get("locale"));
} }
static createScripting({ sandboxBundleSrc }) { static createScripting({ sandboxBundleSrc }) {

View File

@ -30,7 +30,7 @@ class GenericL10n extends L10n {
[], [],
GenericL10n.#generateBundles.bind( GenericL10n.#generateBundles.bind(
GenericL10n, GenericL10n,
"en-US", "en-us",
this.getLanguage() this.getLanguage()
) )
) )

View File

@ -16,6 +16,8 @@
/** @typedef {import("./interfaces").IL10n} IL10n */ /** @typedef {import("./interfaces").IL10n} IL10n */
/** /**
* NOTE: The L10n-implementations should use lowercase language-codes
* internally.
* @implements {IL10n} * @implements {IL10n}
*/ */
class L10n { class L10n {
@ -86,24 +88,27 @@ class L10n {
} }
static #fixupLangCode(langCode) { static #fixupLangCode(langCode) {
// Use only lowercase language-codes internally, and fallback to English.
langCode = langCode?.toLowerCase() || "en-us";
// Try to support "incompletely" specified language codes (see issue 13689). // Try to support "incompletely" specified language codes (see issue 13689).
const PARTIAL_LANG_CODES = { const PARTIAL_LANG_CODES = {
en: "en-US", en: "en-us",
es: "es-ES", es: "es-es",
fy: "fy-NL", fy: "fy-nl",
ga: "ga-IE", ga: "ga-ie",
gu: "gu-IN", gu: "gu-in",
hi: "hi-IN", hi: "hi-in",
hy: "hy-AM", hy: "hy-am",
nb: "nb-NO", nb: "nb-no",
ne: "ne-NP", ne: "ne-np",
nn: "nn-NO", nn: "nn-no",
pa: "pa-IN", pa: "pa-in",
pt: "pt-PT", pt: "pt-pt",
sv: "sv-SE", sv: "sv-se",
zh: "zh-CN", zh: "zh-cn",
}; };
return PARTIAL_LANG_CODES[langCode?.toLowerCase()] || langCode; return PARTIAL_LANG_CODES[langCode] || langCode;
} }
static #isRTL(lang) { static #isRTL(lang) {

View File

@ -50,7 +50,7 @@ class ConstL10n extends L10n {
} }
static get instance() { static get instance() {
return shadow(this, "instance", new ConstL10n("en-US")); return shadow(this, "instance", new ConstL10n("en-us"));
} }
} }

View File

@ -19,7 +19,7 @@ import { PDFDateString, PromiseCapability } from "pdfjs-lib";
const DEFAULT_FIELD_CONTENT = "-"; const DEFAULT_FIELD_CONTENT = "-";
// See https://en.wikibooks.org/wiki/Lentis/Conversion_to_the_Metric_Standard_in_the_United_States // See https://en.wikibooks.org/wiki/Lentis/Conversion_to_the_Metric_Standard_in_the_United_States
const NON_METRIC_LOCALES = ["en-US", "en-LR", "my"]; const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
// Should use the format: `width x height`, in portrait orientation. The names, // Should use the format: `width x height`, in portrait orientation. The names,
// which are l10n-ids, should be lowercase. // which are l10n-ids, should be lowercase.