(fix) move luxon configuration to locale.ts plugin, where config actually is defined

This commit is contained in:
Valentyne Stigloher 2025-02-17 16:54:44 +01:00
parent 08788dfff5
commit 1f16d81df7
2 changed files with 10 additions and 8 deletions

View File

@ -1,4 +1,4 @@
import { DateTime, Settings } from 'luxon';
import { DateTime } from 'luxon';
import { defineNuxtPlugin, useCookie, useRouter } from 'nuxt/app';
import type { Pinia } from 'pinia';
import { decodeTime } from 'ulid';
@ -129,13 +129,6 @@ export default defineNuxtPlugin((nuxtApp) => {
});
};
try {
Settings.defaultLocale = config.intlLocale || config.locale;
DateTime.now().toFormat('y-MM-dd HH:mm'); // test if locale is supported by luxon
} catch {
Settings.defaultLocale = 'en';
}
const datetime = (timestamp: number): string => {
const dt = DateTime.fromSeconds(timestamp);
return dt.toFormat('y-MM-dd HH:mm');

View File

@ -1,3 +1,5 @@
import { DateTime, Settings } from 'luxon';
import baseTranslations from '~/locale/_base/translations.suml';
import type { Translations } from '~/locale/translations.ts';
import buildLocaleList from '~/src/buildLocaleList.ts';
@ -60,6 +62,13 @@ export default defineNuxtPlugin({
}
});
try {
Settings.defaultLocale = config.intlLocale || config.locale;
DateTime.now().toFormat('y-MM-dd HH:mm'); // test if locale is supported by luxon
} catch {
Settings.defaultLocale = 'en';
}
return {
provide: {
// identifier must be different to config because it is already reserved for Nuxt runtime config