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

This commit is contained in:
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

View file

@ -6,6 +6,7 @@ let { modelValue } = $defineModel<{
}>()
const { t } = useI18n()
const userSettings = useUserSettings()
const languageKeyword = $ref('')
@ -17,9 +18,22 @@ const fuse = new Fuse(languagesNameList, {
const languages = $computed(() =>
languageKeyword.trim()
? fuse.search(languageKeyword).map(r => r.item)
: [...languagesNameList].sort(({ code: a }, { code: b }) => {
return a === modelValue ? -1 : b === modelValue ? 1 : a.localeCompare(b)
}),
: [...languagesNameList].filter(entry => !userSettings.value.disabledTranslationLanguages.includes(entry.code))
.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) {
@ -38,6 +52,18 @@ function chooseLanguage(language: string) {
>
</div>
<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
v-for="{ code, nativeName, name } in languages"
:key="code"