webapp: Apply correct datetime format based on current locale in HomeView
This commit is contained in:
parent
a08f4a7052
commit
ef8c3a3d42
@ -1,3 +1,4 @@
|
|||||||
|
import type { I18nOptions } from "vue-i18n";
|
||||||
import en from './en.json'
|
import en from './en.json'
|
||||||
import de from './de.json'
|
import de from './de.json'
|
||||||
import fr from './fr.json'
|
import fr from './fr.json'
|
||||||
@ -14,10 +15,46 @@ export const LOCALES = [
|
|||||||
{ value: Locales.FR, caption: 'Français' },
|
{ value: Locales.FR, caption: 'Français' },
|
||||||
]
|
]
|
||||||
|
|
||||||
export const messages = {
|
export const messages: I18nOptions["messages"] = {
|
||||||
[Locales.EN]: en,
|
[Locales.EN]: en,
|
||||||
[Locales.DE]: de,
|
[Locales.DE]: de,
|
||||||
[Locales.FR]: fr,
|
[Locales.FR]: fr,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const dateTimeFormats: I18nOptions["datetimeFormats"] = {
|
||||||
|
[Locales.EN]: {
|
||||||
|
'datetime': {
|
||||||
|
hour: 'numeric',
|
||||||
|
minute: 'numeric',
|
||||||
|
second: 'numeric',
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'numeric',
|
||||||
|
day: 'numeric',
|
||||||
|
hour12: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[Locales.DE]: {
|
||||||
|
'datetime': {
|
||||||
|
hour: 'numeric',
|
||||||
|
minute: 'numeric',
|
||||||
|
second: 'numeric',
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'numeric',
|
||||||
|
day: 'numeric',
|
||||||
|
hour12: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[Locales.FR]: {
|
||||||
|
'datetime': {
|
||||||
|
hour: 'numeric',
|
||||||
|
minute: 'numeric',
|
||||||
|
second: 'numeric',
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'numeric',
|
||||||
|
day: 'numeric',
|
||||||
|
hour12: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const defaultLocale = Locales.EN;
|
export const defaultLocale = Locales.EN;
|
||||||
@ -2,7 +2,7 @@ import mitt from 'mitt'
|
|||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
import { createI18n } from 'vue-i18n'
|
import { createI18n } from 'vue-i18n'
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
import { defaultLocale, messages } from './locales'
|
import { defaultLocale, messages, dateTimeFormats } from './locales'
|
||||||
import { tooltip } from './plugins/bootstrap'
|
import { tooltip } from './plugins/bootstrap'
|
||||||
import router from './router'
|
import router from './router'
|
||||||
|
|
||||||
@ -21,7 +21,8 @@ const i18n = createI18n({
|
|||||||
globalInjection: true,
|
globalInjection: true,
|
||||||
locale: navigator.language.split('-')[0],
|
locale: navigator.language.split('-')[0],
|
||||||
fallbackLocale: defaultLocale,
|
fallbackLocale: defaultLocale,
|
||||||
messages
|
messages,
|
||||||
|
datetimeFormats: dateTimeFormats,
|
||||||
})
|
})
|
||||||
|
|
||||||
app.use(router)
|
app.use(router)
|
||||||
|
|||||||
@ -662,9 +662,8 @@ export default defineComponent({
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
calculateAbsoluteTime(lastTime: number): string {
|
calculateAbsoluteTime(lastTime: number): string {
|
||||||
const userLocale = navigator.language;
|
|
||||||
const date = new Date(Date.now() - lastTime * 1000);
|
const date = new Date(Date.now() - lastTime * 1000);
|
||||||
return date.toLocaleString(userLocale)
|
return this.$d(date, 'datetime');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user