mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender-pwa.git
synced 2025-08-07 12:19:17 +02:00
feat:#60 added switch button (not working)
This commit is contained in:
39
frontend/src/components/LocaleSwitcher.vue
Normal file
39
frontend/src/components/LocaleSwitcher.vue
Normal file
@@ -0,0 +1,39 @@
|
||||
<script lang="ts" setup>
|
||||
import i18n, { supportedLocales } from "../i18n";
|
||||
import { Ref, ref } from "vue";
|
||||
import router from "../router";
|
||||
import { useI18n } from "vue-i18n";
|
||||
|
||||
const locales = ref(
|
||||
Object.keys(supportedLocales).map((code) => ({
|
||||
code,
|
||||
name: supportedLocales[code].name,
|
||||
})),
|
||||
);
|
||||
|
||||
// selectedLocal is the string of the selected locale from i18n matched with the locales array
|
||||
const selectedLocale: Ref<any> = ref();
|
||||
|
||||
const i18n1 = (i18n.vueI18n);
|
||||
|
||||
function onLocaleChange() {
|
||||
const newLocale: string = selectedLocale.value.code;
|
||||
|
||||
// If the selected locale is the same as the
|
||||
// active one, do nothing
|
||||
if (newLocale === i18n.vueI18n.global.locale) {
|
||||
return;
|
||||
}
|
||||
i18n1.global.locale = newLocale;
|
||||
router.push(`/${newLocale}`);
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<Dropdown
|
||||
:options="locales"
|
||||
optionLabel="name"
|
||||
v-model="selectedLocale"
|
||||
@change="onLocaleChange"
|
||||
>
|
||||
</Dropdown>
|
||||
</template>
|
Reference in New Issue
Block a user