Merge pull request #13696 from Snuffleupagus/issue-13689
[GENERIC viewer] Try to fixup "incomplete" language codes (issue 13689)
This commit is contained in:
commit
62b5dc9eb7
@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import "../external/webL10n/l10n.js";
|
import "../external/webL10n/l10n.js";
|
||||||
import { getL10nFallback } from "./l10n_utils.js";
|
import { fixupLangCode, getL10nFallback } from "./l10n_utils.js";
|
||||||
|
|
||||||
const webL10n = document.webL10n;
|
const webL10n = document.webL10n;
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ class GenericL10n {
|
|||||||
constructor(lang) {
|
constructor(lang) {
|
||||||
this._lang = lang;
|
this._lang = lang;
|
||||||
this._ready = new Promise((resolve, reject) => {
|
this._ready = new Promise((resolve, reject) => {
|
||||||
webL10n.setLanguage(lang, () => {
|
webL10n.setLanguage(fixupLangCode(lang), () => {
|
||||||
resolve(webL10n);
|
resolve(webL10n);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -95,6 +95,28 @@ function getL10nFallback(key, args) {
|
|||||||
return DEFAULT_L10N_STRINGS[key] || "";
|
return DEFAULT_L10N_STRINGS[key] || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PARTIAL_LANG_CODES = {
|
||||||
|
en: "en-US",
|
||||||
|
es: "es-ES",
|
||||||
|
fy: "fy-NL",
|
||||||
|
ga: "ga-IE",
|
||||||
|
gu: "gu-IN",
|
||||||
|
hi: "hi-IN",
|
||||||
|
hy: "hy-AM",
|
||||||
|
nb: "nb-NO",
|
||||||
|
ne: "ne-NP",
|
||||||
|
nn: "nn-NO",
|
||||||
|
pa: "pa-IN",
|
||||||
|
pt: "pt-PT",
|
||||||
|
sv: "sv-SE",
|
||||||
|
zh: "zh-CN",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Try to support "incompletely" specified language codes (see issue 13689).
|
||||||
|
function fixupLangCode(langCode) {
|
||||||
|
return PARTIAL_LANG_CODES[langCode?.toLowerCase()] || langCode;
|
||||||
|
}
|
||||||
|
|
||||||
// Replaces {{arguments}} with their values.
|
// Replaces {{arguments}} with their values.
|
||||||
function formatL10nValue(text, args) {
|
function formatL10nValue(text, args) {
|
||||||
if (!args) {
|
if (!args) {
|
||||||
@ -125,4 +147,4 @@ const NullL10n = {
|
|||||||
async translate(element) {},
|
async translate(element) {},
|
||||||
};
|
};
|
||||||
|
|
||||||
export { getL10nFallback, NullL10n };
|
export { fixupLangCode, getL10nFallback, NullL10n };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user