feat: add v-model capabilities to LocaleSwitcher component
This commit is contained in:
parent
9757a3d076
commit
d72c3efeeb
1 changed files with 28 additions and 9 deletions
|
@ -1,19 +1,38 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const localeFlags = {
|
import { computed } from "vue";
|
||||||
en: "🇬🇧 English",
|
|
||||||
de: "🇩🇪 Deutsch",
|
interface LocaleOption {
|
||||||
};
|
code: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
modelValue: string;
|
||||||
|
locales: LocaleOption[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = defineProps<Props>();
|
||||||
|
const emit = defineEmits(["update:modelValue"]);
|
||||||
|
|
||||||
|
const selectModel = computed({
|
||||||
|
get() {
|
||||||
|
return props.modelValue;
|
||||||
|
},
|
||||||
|
set(value) {
|
||||||
|
emit("update:modelValue", value);
|
||||||
|
},
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="localeswitch">
|
<div class="localeswitch">
|
||||||
<select v-model="$i18n.locale">
|
<select v-model="selectModel">
|
||||||
<option
|
<option
|
||||||
v-for="locale in $i18n.availableLocales"
|
v-for="locale in locales"
|
||||||
:key="`locale-${locale}`"
|
:key="`locale-${locale.code}`"
|
||||||
:value="locale"
|
:value="locale.code"
|
||||||
>
|
>
|
||||||
{{ localeFlags[locale] }}
|
{{ locale.name }}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue