added locale
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
<script lang="ts" >
|
<script lang="ts" >
|
||||||
import {RouterView} from 'vue-router';
|
import {RouterView} from 'vue-router';
|
||||||
import {Options, Vue} from 'vue-class-component';
|
import {Options, Vue} from 'vue-class-component';
|
||||||
|
import DocumentLocaleSetter from '@/components/locale/DocumentLocaleSetter.vue';
|
||||||
|
|
||||||
@Options({
|
@Options({
|
||||||
name: 'App',
|
name: 'App',
|
||||||
components: {
|
components: {
|
||||||
|
DocumentLocaleSetter,
|
||||||
RouterView,
|
RouterView,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -14,5 +16,6 @@ export default class App extends Vue {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
<DocumentLocaleSetter/>
|
||||||
<RouterView/>
|
<RouterView/>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
20
src/components/locale/DocumentLocaleSetter.vue
Normal file
20
src/components/locale/DocumentLocaleSetter.vue
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import {Vue, Options} from 'vue-class-component';
|
||||||
|
import {setDocumentLocale} from '@/locale/locale';
|
||||||
|
import {Watch} from 'vue-property-decorator';
|
||||||
|
|
||||||
|
@Options({name: 'DocumentLocaleSetter'})
|
||||||
|
export default class DocumentLocaleSetter extends Vue {
|
||||||
|
mounted(): void {
|
||||||
|
this.onLocaleChanged(this.$i18n.locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Watch('$i18n.locale')
|
||||||
|
onLocaleChanged(value: string): void {
|
||||||
|
setDocumentLocale(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
</template>
|
||||||
24
src/locale/de.ts
Normal file
24
src/locale/de.ts
Normal file
@@ -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',
|
||||||
|
},
|
||||||
|
};
|
||||||
24
src/locale/en.ts
Normal file
24
src/locale/en.ts
Normal file
@@ -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',
|
||||||
|
},
|
||||||
|
};
|
||||||
28
src/locale/locale.ts
Normal file
28
src/locale/locale.ts
Normal file
@@ -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);
|
||||||
|
}
|
||||||
@@ -4,9 +4,12 @@ import {createPinia} from 'pinia';
|
|||||||
import App from './App.vue';
|
import App from './App.vue';
|
||||||
import router from './router';
|
import router from './router';
|
||||||
|
|
||||||
|
import {createI18n} from '@/locale/locale';
|
||||||
|
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
|
|
||||||
app.use(createPinia());
|
app.use(createPinia());
|
||||||
app.use(router);
|
app.use(router);
|
||||||
|
app.use(createI18n());
|
||||||
|
|
||||||
app.mount('#app');
|
app.mount('#app');
|
||||||
|
|||||||
Reference in New Issue
Block a user