mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-22 01:15:25 +03:00
feat: prioritize user languages in language picker (#1614)
This commit is contained in:
parent
297b104e1c
commit
76bad723ab
1 changed files with 29 additions and 3 deletions
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue