feat:#60 added localization switch

This commit is contained in:
masterelmar
2023-11-15 12:46:56 +01:00
parent 3f1a592468
commit 00399c32d9
11 changed files with 204 additions and 98 deletions

View File

@@ -1,23 +1,25 @@
import { createI18n } from "vue-i18n";
import { nextTick } from "vue";
import defaultMessages from './translations/en.json'
import en from './translations/en.json'
import de from './translations/de.json'
import localeStore from "../store/localeStore.ts";
export const supportedLocales= {
'en': { name: 'English'},
'de': { name: 'Deutsch'},
}
export let defaultLocale = 'en'
// Private instance of VueI18n object
let _i18n: any
// Initializer
function setup(options = { locale: defaultLocale }) {
function setup() {
_i18n = createI18n({
legacy: false,
locale: options.locale,
fallbackLocale: defaultLocale,
messages: { [defaultLocale]: defaultMessages },
locale: localeStore().locale,
fallbackLocale: "en",
messages: {
en,
de
},
})
setLocale(options.locale)
return _i18n
}
@@ -27,16 +29,6 @@ function setLocale(newLocale : any) {
setDocumentAttributesFor(newLocale)
}
async function loadMessagesFor(locale: any) {
const messages = await import(
`./translations/${locale}.json`
)
_i18n.global.setLocaleMessage(locale, messages.default)
return nextTick()
}
function setDocumentAttributesFor(locale: any) {
const htmlElement = document.querySelector('html')
@@ -51,5 +43,4 @@ export default {
},
setup,
setLocale,
loadMessagesFor,
}

View File

@@ -4,5 +4,12 @@
"roomFinder": "Raumfinder",
"faq": "FAQ",
"imprint": "Impressum",
"privacy": "Datenschutz"
"privacy": "Datenschutz",
"english": "Englisch",
"german": "Deutsch",
"courseSelection": {
"winterSemester": "Wintersemester",
"summerSemester": "Sommersemester",
"selectCourse": "Bitte wähle eine Gruppe und das Semester aus"
}
}

View File

@@ -4,5 +4,12 @@
"roomFinder": "Room Finder",
"faq": "FAQ",
"imprint": "Imprint",
"privacy": "Privacy"
"privacy": "Privacy",
"english": "English",
"german": "German",
"courseSelection": {
"winterSemester": "winter semester",
"summerSemester": "summer semester",
"selectCourse": "Please select a course and semester"
}
}