mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-03 10:19:14 +02:00
feat:#60 added localization switch
This commit is contained in:
@@ -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,
|
||||
}
|
@@ -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"
|
||||
}
|
||||
}
|
@@ -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"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user