minor refactor

This commit is contained in:
naskya 2023-11-23 04:24:21 +09:00
parent d8a8fc8f7a
commit 09a6527cee
No known key found for this signature in database
GPG key ID: 164DFF24E2D40139

View file

@ -704,15 +704,15 @@ function setVisibility() {
} }
// example usage: // example usage:
// filterLangmapByKeyPrefix("zh") to take // filterLangmapByPrefix("zh") to take
// "zh", "zh-cn", "zh-tw", "zh-hk", etc. out of the langmap // "zh", "zh-cn", "zh-tw", "zh-hk", etc. out of the langmap
function filterLangmapByKeyPrefix( function filterLangmapByPrefix(
prefix: string, prefix: string,
): { langKey: string; nativeName: string }[] { ): { langCode: string; nativeName: string }[] {
return Object.keys(langmap) return Object.entries(langmap)
.filter((key) => key.startsWith(prefix)) .filter(([langCode, _]) => langCode.startsWith(prefix))
.map((key) => { .map(([langCode, v]) => {
return { langKey: key, nativeName: langmap[key].nativeName }; return { langCode, nativeName: v.nativeName };
}); });
} }
@ -729,13 +729,13 @@ function setLanguage() {
type: "label", type: "label",
text: i18n.ts.suggested, text: i18n.ts.suggested,
}); });
filterLangmapByKeyPrefix(detectedLanguage).forEach((v, i) => { filterLangmapByPrefix(detectedLanguage).forEach((v) => {
actions.push({ actions.push({
text: v.nativeName, text: v.nativeName,
danger: false, danger: false,
active: false, active: false,
action: () => { action: () => {
language.value = v.langKey; language.value = v.langCode;
}, },
}); });
}); });