Re-factor the L10n
-implementations to use lowercase language-codes internally
This is consistent with the implementation used in the (now removed) webL10n-library, and by only using lowercase language-codes internally in the `L10n`-implementations we should avoid future issues e.g. when users manually set the `locale`-option (in the default viewer).
This commit is contained in:
parent
44cde3ccca
commit
1f9533bae9
@ -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([
|
||||||
|
@ -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 }) {
|
||||||
|
@ -30,7 +30,7 @@ class GenericL10n extends L10n {
|
|||||||
[],
|
[],
|
||||||
GenericL10n.#generateBundles.bind(
|
GenericL10n.#generateBundles.bind(
|
||||||
GenericL10n,
|
GenericL10n,
|
||||||
"en-US",
|
"en-us",
|
||||||
this.getLanguage()
|
this.getLanguage()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
35
web/l10n.js
35
web/l10n.js
@ -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) {
|
||||||
|
@ -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"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user