diff --git a/src/App.vue b/src/App.vue index 8be77f2..3cd64e6 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,10 +1,12 @@ diff --git a/src/components/locale/DocumentLocaleSetter.vue b/src/components/locale/DocumentLocaleSetter.vue new file mode 100644 index 0000000..c5392ea --- /dev/null +++ b/src/components/locale/DocumentLocaleSetter.vue @@ -0,0 +1,20 @@ + + + diff --git a/src/locale/de.ts b/src/locale/de.ts new file mode 100644 index 0000000..fe5af10 --- /dev/null +++ b/src/locale/de.ts @@ -0,0 +1,24 @@ +export const messagesDe = {}; + +export const datetimeFormatsDe = { + date: { + year: 'numeric', + month: 'numeric', + day: 'numeric', + }, + datetime: { + year: 'numeric', + month: 'numeric', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + }, + datetimeSeconds: { + year: 'numeric', + month: 'numeric', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + seconds: 'numeric', + }, +}; \ No newline at end of file diff --git a/src/locale/en.ts b/src/locale/en.ts new file mode 100644 index 0000000..196ec89 --- /dev/null +++ b/src/locale/en.ts @@ -0,0 +1,24 @@ +export const messagesEn = {}; + +export const datetimeFormatsEn = { + date: { + year: 'numeric', + month: 'numeric', + day: 'numeric', + }, + datetime: { + year: 'numeric', + month: 'numeric', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + }, + datetimeSeconds: { + year: 'numeric', + month: 'numeric', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + seconds: 'numeric', + }, +}; \ No newline at end of file diff --git a/src/locale/locale.ts b/src/locale/locale.ts new file mode 100644 index 0000000..987de8d --- /dev/null +++ b/src/locale/locale.ts @@ -0,0 +1,28 @@ +import type {I18n} from 'vue-i18n'; +import {createI18n as vueCreateI18n} from 'vue-i18n'; +import {messagesEn, datetimeFormatsEn} from '@/locale/en'; +import {messagesDe, datetimeFormatsDe} from '@/locale/de'; + +const messages = { + en: messagesEn, + de: messagesDe, +} + +const datetimeFormats = { + en: datetimeFormatsEn, + de: datetimeFormatsDe, +} + +export function createI18n(): I18n { + return vueCreateI18n({ + locale: 'de', + fallbackLocale: 'en', + messages: messages, + datetimeFormats: datetimeFormats, + legacy: true, + }); +} + +export function setDocumentLocale(locale: string): void { + document.documentElement.setAttribute("lang", locale); +} diff --git a/src/main.ts b/src/main.ts index 1e05147..48e56b9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,9 +4,12 @@ import {createPinia} from 'pinia'; import App from './App.vue'; import router from './router'; +import {createI18n} from '@/locale/locale'; + const app = createApp(App); app.use(createPinia()); app.use(router); +app.use(createI18n()); app.mount('#app');