fix:#5 added translation and test i18n for default primevue locale

This commit is contained in:
Elmar Kresse
2024-01-26 20:17:46 +01:00
parent e5571e899c
commit 69783c5566
5 changed files with 264 additions and 38 deletions

View File

@@ -2,12 +2,14 @@ import { createI18n } from "vue-i18n";
import en from "./translations/en.json";
import de from "./translations/de.json";
import localeStore from "../store/localeStore.ts";
import { usePrimeVue } from "primevue/config";
export const supportedLocales = {
en: { name: "English" },
de: { name: "Deutsch" },
};
// Private instance of VueI18n object
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let _i18n: any;
// Initializer
function setup() {
@@ -24,12 +26,14 @@ function setup() {
}
// Sets the active locale.
function setLocale(newLocale: any) {
function setLocale(newLocale: string) {
_i18n.global.locale = newLocale;
setDocumentAttributesFor(newLocale);
const primeVue = usePrimeVue();
primeVue.config.locale = Object.assign(_i18n);
}
function setDocumentAttributesFor(locale: any) {
function setDocumentAttributesFor(locale: string) {
const htmlElement = document.querySelector("html");
htmlElement?.setAttribute("lang", locale);