2023-01-04 12:56:10 +03:00
|
|
|
<script setup lang="ts">
|
|
|
|
import Fuse from 'fuse.js'
|
|
|
|
|
2023-08-01 12:43:55 +03:00
|
|
|
const modelValue = defineModel<string>({ required: true })
|
2023-01-04 12:56:10 +03:00
|
|
|
|
|
|
|
const { t } = useI18n()
|
2023-02-05 18:14:26 +03:00
|
|
|
const userSettings = useUserSettings()
|
2023-01-04 12:56:10 +03:00
|
|
|
|
2024-02-21 18:20:08 +03:00
|
|
|
const languageKeyword = ref('')
|
2023-01-04 12:56:10 +03:00
|
|
|
|
2023-01-30 14:09:04 +03:00
|
|
|
const fuse = new Fuse(languagesNameList, {
|
2023-01-04 12:56:10 +03:00
|
|
|
keys: ['code', 'nativeName', 'name'],
|
|
|
|
shouldSort: true,
|
|
|
|
})
|
|
|
|
|
2024-02-21 18:20:08 +03:00
|
|
|
const languages = computed(() =>
|
|
|
|
languageKeyword.value.trim()
|
|
|
|
? fuse.search(languageKeyword.value).map(r => r.item)
|
2024-09-30 11:11:56 +03:00
|
|
|
: [...languagesNameList].filter(entry => !userSettings.value.disabledTranslationLanguages.includes(entry.code)).sort(({ code: a }, { code: b }) => {
|
|
|
|
// Put English on the top
|
|
|
|
if (a === 'en')
|
|
|
|
return -1
|
2023-05-01 20:30:57 +03:00
|
|
|
|
2024-09-30 11:11:56 +03:00
|
|
|
return a === modelValue.value ? -1 : b === modelValue.value ? 1 : a.localeCompare(b)
|
|
|
|
}),
|
2023-02-05 18:14:26 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
},
|
|
|
|
|
2023-01-04 12:56:10 +03:00
|
|
|
)
|
|
|
|
|
2023-01-04 13:21:18 +03:00
|
|
|
function chooseLanguage(language: string) {
|
2023-08-01 12:43:55 +03:00
|
|
|
modelValue.value = language
|
2023-01-04 12:56:10 +03:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2023-01-30 14:20:22 +03:00
|
|
|
<div relative of-x-hidden>
|
|
|
|
<div p2>
|
|
|
|
<input
|
|
|
|
v-model="languageKeyword"
|
|
|
|
:placeholder="t('language.search')"
|
|
|
|
p2 border-rounded w-full bg-transparent
|
|
|
|
outline-none border="~ base"
|
|
|
|
>
|
|
|
|
</div>
|
2023-01-04 12:56:10 +03:00
|
|
|
<div max-h-40vh overflow-auto>
|
2023-02-05 18:14:26 +03:00
|
|
|
<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>
|
|
|
|
|
2023-01-04 12:56:10 +03:00
|
|
|
<CommonDropdownItem
|
|
|
|
v-for="{ code, nativeName, name } in languages"
|
|
|
|
:key="code"
|
2023-01-04 13:21:18 +03:00
|
|
|
:text="nativeName"
|
|
|
|
:description="name"
|
|
|
|
:checked="code === modelValue"
|
2023-01-04 12:56:10 +03:00
|
|
|
@click="chooseLanguage(code)"
|
2023-01-04 13:21:18 +03:00
|
|
|
/>
|
2023-01-04 12:56:10 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|