fix(i18n): use actually set language for dates

This fixes a bug where a translated string was used as the locale for dates, instead of the actually configured locale.

Resolves https://github.com/go-vikunja/vikunja/issues/391
This commit is contained in:
kolaente 2025-03-09 10:24:45 +01:00
parent 5db22c9964
commit 4e979f3375
No known key found for this signature in database
GPG Key ID: F40E70337AB24C9B
3 changed files with 8 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import dayjs from 'dayjs'
import {i18n} from '@/i18n'
import {createSharedComposable} from '@vueuse/core'
import {computed, toValue, type MaybeRefOrGetter} from 'vue'
import {DAYJS_LOCALE_MAPPING} from '@/i18n/useDayjsLanguageSync.ts'
export function dateIsValid(date: Date | null) {
if (date === null) {
@ -13,12 +14,14 @@ export function dateIsValid(date: Date | null) {
return date instanceof Date && !isNaN(date)
}
export const formatDate = (date: Date | string | null, f: string, locale = i18n.global.t('date.locale')) => {
export const formatDate = (date: Date | string | null, f: string) => {
if (!dateIsValid(date)) {
return ''
}
date = createDateFromString(date)
const locale = DAYJS_LOCALE_MAPPING[i18n.global.locale.value.toLowerCase()] ?? 'en'
return date
? dayjs(date).locale(locale).format(f)
@ -33,13 +36,15 @@ export function formatDateShort(date) {
return formatDate(date, 'lll')
}
export const formatDateSince = (date: Date | string | null, locale = i18n.global.t('date.locale')) => {
export const formatDateSince = (date: Date | string | null) => {
if (!dateIsValid(date)) {
return ''
}
date = createDateFromString(date)
const locale = DAYJS_LOCALE_MAPPING[i18n.global.locale.value.toLowerCase()] ?? 'en'
return date
? dayjs(date).locale(locale).fromNow()
: ''

View File

@ -1130,7 +1130,6 @@
}
},
"date": {
"locale": "en",
"altFormatLong": "j M Y, H:i",
"altFormatShort": "j M Y"
},

View File

@ -61,7 +61,7 @@ export async function loadDayJsLocale(language: SupportedLocale) {
if (language === 'en') {
return
}
await DAYJS_LANGUAGE_IMPORTS[language.toLowerCase()]()
}