feat: prioritize user languages in language picker (#1614)

zio/stable
Niklas Wolf 2023-02-05 16:14:26 +01:00 committed by GitHub
parent 297b104e1c
commit 76bad723ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 3 deletions

View File

@ -6,6 +6,7 @@ let { modelValue } = $defineModel<{
}>() }>()
const { t } = useI18n() const { t } = useI18n()
const userSettings = useUserSettings()
const languageKeyword = $ref('') const languageKeyword = $ref('')
@ -17,9 +18,22 @@ const fuse = new Fuse(languagesNameList, {
const languages = $computed(() => const languages = $computed(() =>
languageKeyword.trim() languageKeyword.trim()
? fuse.search(languageKeyword).map(r => r.item) ? fuse.search(languageKeyword).map(r => r.item)
: [...languagesNameList].sort(({ code: a }, { code: b }) => { : [...languagesNameList].filter(entry => !userSettings.value.disabledTranslationLanguages.includes(entry.code))
return a === modelValue ? -1 : b === modelValue ? 1 : a.localeCompare(b) .sort(({ code: a }, { code: b }) => {
}), return a === modelValue ? -1 : b === modelValue ? 1 : a.localeCompare(b)
}),
)
const preferredLanguages = computed(() => {
const result = []
for (const langCode of userSettings.value.disabledTranslationLanguages) {
const completeLang = languagesNameList.find(listEntry => listEntry.code === langCode)
if (completeLang)
result.push(completeLang)
}
return result
},
) )
function chooseLanguage(language: string) { function chooseLanguage(language: string) {
@ -38,6 +52,18 @@ function chooseLanguage(language: string) {
> >
</div> </div>
<div max-h-40vh overflow-auto> <div max-h-40vh overflow-auto>
<template v-if="!languageKeyword.trim()">
<CommonDropdownItem
v-for="{ code, nativeName, name } in preferredLanguages"
:key="code"
:text="nativeName"
:description="name"
:checked="code === modelValue"
@click="chooseLanguage(code)"
/>
<hr class="border-base ">
</template>
<CommonDropdownItem <CommonDropdownItem
v-for="{ code, nativeName, name } in languages" v-for="{ code, nativeName, name } in languages"
:key="code" :key="code"