suggest all options if multiple regions are defined in the langmap

This commit is contained in:
naskya 2023-11-22 23:19:14 +09:00
parent 8126c15677
commit 061791eb65
No known key found for this signature in database
GPG key ID: 164DFF24E2D40139
3 changed files with 28 additions and 9 deletions

View file

@ -1156,6 +1156,7 @@ detectPostLanguage: "Automatically detect the language and show a translate butt
vibrate: "Play vibrations"
openServerInfo: "Show server information by clicking the server ticker on a post"
iconSet: "Icon set"
suggested: "Suggested"
_sensitiveMediaDetection:
description: "Reduces the effort of server moderation through automatically recognizing

View file

@ -2003,3 +2003,4 @@ _iconSets:
regular: "標準"
fill: "塗りつぶし"
duotone: "2色"
suggested: "候補"

View file

@ -703,6 +703,19 @@ function setVisibility() {
);
}
// example usage:
// filterLangmapByKeyPrefix("zh") to take
// "zh", "zh-cn", "zh-tw", "zh-hk", etc. out of the langmap
function filterLangmapByKeyPrefix(
prefix: string,
): { langKey: string; nativeName: string }[] {
return Object.keys(langmap)
.filter((key) => key.startsWith(prefix))
.map((key) => {
return { langKey: key, nativeName: langmap[key].nativeName };
});
}
function setLanguage() {
const actions: Array<MenuItem> = [];
@ -711,19 +724,23 @@ function setLanguage() {
detectedLanguage !== "" &&
detectedLanguage != null &&
detectedLanguage !== language.value
)
actions.push(
{
text: langmap[detectedLanguage].nativeName,
) {
actions.push({
type: "label",
text: i18n.ts.suggested,
});
filterLangmapByKeyPrefix(detectedLanguage).forEach((v, i) => {
actions.push({
text: v.nativeName,
danger: false,
active: false,
icon: `${icon("ph-list-magnifying-glass")}`,
action: () => {
language.value = detectedLanguage;
language.value = v.langKey;
},
},
null,
);
});
});
actions.push(null);
}
if (language.value != null)
actions.push({