Fix language switching

This commit is contained in:
Elia Bieri 2023-05-26 10:25:49 +02:00 committed by Daniel Egger
parent 498e9ab232
commit f8e309e424
3 changed files with 14 additions and 8 deletions

View File

@ -1,6 +1,4 @@
import * as Sentry from "@sentry/vue";
import dayjs from "dayjs";
import "dayjs/locale/de";
import * as log from "loglevel";
import { createPinia } from "pinia";
import { createApp, markRaw } from "vue";
@ -39,10 +37,8 @@ Sentry.init({
});
// todo: define lang setup
const locale = "de";
loadLocaleMessages(locale).then(() => {
loadLocaleMessages("de").then(() => {
app.use(router);
dayjs.locale(locale);
const pinia = createPinia();
pinia.use(({ store }) => {

View File

@ -19,7 +19,6 @@
<script setup lang="ts">
import type { CourseSessionAttendanceCourse } from "@/types";
import dayjs from "dayjs";
import "dayjs/locale/de";
import LocalizedFormat from "dayjs/plugin/localizedFormat";
import { computed } from "vue";
@ -30,8 +29,7 @@ export interface Props {
const props = defineProps<Props>();
dayjs.extend(LocalizedFormat);
dayjs.locale("de");
const format = "LLLL [Uhr]";
const format = "LLLL";
const start = computed(() => dayjs(props.attendanceCourse.start).format(format));
const end = computed(() => dayjs(props.attendanceCourse.end).format(format));
const location = computed(() => props.attendanceCourse.location);

View File

@ -2,6 +2,7 @@ import log from "loglevel";
import { bustItGetCache, itGetCached, itPost } from "@/fetchHelpers";
import { loadLocaleMessages, setI18nLanguage } from "@/i18n";
import dayjs from "dayjs";
import { defineStore } from "pinia";
const logoutRedirectUrl = import.meta.env.VITE_LOGOUT_REDIRECT || "/";
@ -36,6 +37,17 @@ const initialUserState: UserState = {
};
async function setLocale(language: AvailableLanguages) {
switch (language) {
case "de":
await import("dayjs/locale/de");
break;
case "fr":
await import("dayjs/locale/fr");
break;
case "it":
await import("dayjs/locale/it");
}
dayjs.locale(language);
await loadLocaleMessages(language);
setI18nLanguage(language);
}