webapp: Added possibility to manually set the locale

This commit is contained in:
Thomas Basler 2022-12-26 12:24:10 +01:00
parent cb2d4218b5
commit 04ef9c6624
2 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,27 @@
<template>
<select class="form-select" @change="updateLanguage()" v-model="$i18n.locale">
<option v-for="locale in $i18n.availableLocales" :key="`locale-${locale}`" :value="locale">
{{ locale.toUpperCase() }}
</option>
</select>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
name: "LocaleSwitcher",
methods: {
updateLanguage() {
localStorage.setItem("locale", this.$i18n.locale);
},
},
mounted() {
if (localStorage.getItem("locale")) {
this.$i18n.locale = localStorage.getItem("locale") || "en";
} else {
localStorage.setItem("locale", this.$i18n.locale);
}
},
});
</script>

View File

@ -93,6 +93,7 @@
</li> </li>
</ul> </ul>
<form class="d-flex" role="search"> <form class="d-flex" role="search">
<LocaleSwitcher class="me-2" />
<button v-if="isLogged" class="btn btn-outline-danger" @click="signout">{{ $t('menu.Logout') }}</button> <button v-if="isLogged" class="btn btn-outline-danger" @click="signout">{{ $t('menu.Logout') }}</button>
<button v-if="!isLogged" class="btn btn-outline-success" @click="signin">{{ $t('menu.Login') }}</button> <button v-if="!isLogged" class="btn btn-outline-success" @click="signin">{{ $t('menu.Login') }}</button>
</form> </form>
@ -105,12 +106,14 @@
import { isLoggedIn, logout } from '@/utils/authentication'; import { isLoggedIn, logout } from '@/utils/authentication';
import { BIconEgg, BIconSun, BIconTree } from 'bootstrap-icons-vue'; import { BIconEgg, BIconSun, BIconTree } from 'bootstrap-icons-vue';
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import LocaleSwitcher from './LocaleSwitcher.vue';
export default defineComponent({ export default defineComponent({
components: { components: {
BIconEgg, BIconEgg,
BIconSun, BIconSun,
BIconTree, BIconTree,
LocaleSwitcher,
}, },
data() { data() {
return { return {