minor refactor
This commit is contained in:
parent
d8a8fc8f7a
commit
09a6527cee
1 changed files with 9 additions and 9 deletions
|
@ -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;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue