update langmap to sort out issues regarding Chinese locales

This commit is contained in:
naskya 2023-11-23 19:48:33 +09:00
parent 610722e258
commit e5163ecb82
No known key found for this signature in database
GPG key ID: 164DFF24E2D40139
2 changed files with 15 additions and 16 deletions

View file

@ -714,17 +714,22 @@ const language = ref<string>(
localStorage.getItem("lang")?.split("-")[0], localStorage.getItem("lang")?.split("-")[0],
); );
// example usage:
// filterLangmapByPrefix("zh") to take
// zh, zh-cn, zh-tw, zh-hk, etc. out of the langmap
function filterLangmapByPrefix( function filterLangmapByPrefix(
prefix: string, prefix: string,
): { langCode: string; nativeName: string }[] { ): { langCode: string; nativeName: string }[] {
return Object.entries(langmap) const to_return = Object.entries(langmap)
.filter(([langCode, _]) => langCode.startsWith(prefix)) .filter(([langCode, _]) => langCode.startsWith(prefix))
.map(([langCode, v]) => { .map(([langCode, v]) => {
return { langCode, nativeName: v.nativeName }; return { langCode, nativeName: v.nativeName };
}); });
if (prefix === "zh")
to_return = to_return.concat([
{ langCode: "yue", nativeName: langmap["yue"].nativeName },
{ langCode: "nan", nativeName: langmap["nan"].nativeName },
]);
return to_return;
} }
function setLanguage() { function setLanguage() {

View file

@ -354,6 +354,12 @@ export const iso639Langs3 = {
tok: { tok: {
nativeName: "Toki Pona", nativeName: "Toki Pona",
}, },
yue: {
nativeName: "粵語",
},
nan: {
nativeName: "閩南語",
},
}; };
export const langmapNoRegion = Object.assign({}, iso639Langs1, iso639Langs3); export const langmapNoRegion = Object.assign({}, iso639Langs1, iso639Langs3);
@ -365,18 +371,6 @@ export const iso639Regional = {
"zh-hant": { "zh-hant": {
nativeName: "中文(繁體)", nativeName: "中文(繁體)",
}, },
"zh-cn": {
nativeName: "中文(中国大陆)",
},
"zh-hk": {
nativeName: "中文(香港)",
},
"zh-sg": {
nativeName: "中文(新加坡)",
},
"zh-tw": {
nativeName: "中文(台灣)",
},
}; };
export const langmap = Object.assign({}, langmapNoRegion, iso639Regional); export const langmap = Object.assign({}, langmapNoRegion, iso639Regional);