diff --git a/assets/translator.ts b/assets/translator.ts index fe4e14ffa..2daba91aa 100644 --- a/assets/translator.ts +++ b/assets/translator.ts @@ -1,7 +1,12 @@ -import { trans, setLocale, setLocaleFallbacks } from "./ux-translator"; +import { + trans, + setLocale, + getLocale, + setLocaleFallbacks, +} from "./ux-translator"; -setLocaleFallbacks({"en": "fr", "nl": "fr", "fr": "en"}); -setLocale('fr'); +setLocaleFallbacks({ en: "fr", nl: "fr", fr: "en" }); +setLocale("fr"); -export { trans }; -export * from '../var/translations'; +export { trans, getLocale }; +export * from "../var/translations"; diff --git a/src/Bundle/ChillMainBundle/Resources/public/lib/localizationHelper/localizationHelper.ts b/src/Bundle/ChillMainBundle/Resources/public/lib/localizationHelper/localizationHelper.ts index 354c9f8af..3b67da68e 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/lib/localizationHelper/localizationHelper.ts +++ b/src/Bundle/ChillMainBundle/Resources/public/lib/localizationHelper/localizationHelper.ts @@ -1,4 +1,5 @@ -import { TranslatableString } from "ChillMainAssets/types"; +import { DateTime, TranslatableString } from "ChillMainAssets/types"; +import { getLocale } from "translator"; /** * Localizes a translatable string object based on the current locale. @@ -17,11 +18,10 @@ import { TranslatableString } from "ChillMainAssets/types"; * @returns The localized URL */ export function localizedUrl(url: string): string { - const lang = - document.documentElement.lang || navigator.language.split("-")[0] || "fr"; + const locale = getLocale(); // Ensure url starts with a slash and does not already start with /{lang}/ const normalizedUrl = url.startsWith("/") ? url : `/${url}`; - const langPrefix = `/${lang}`; + const langPrefix = `/${locale}`; if (normalizedUrl.startsWith(langPrefix + "/")) { return normalizedUrl; } @@ -36,7 +36,7 @@ export function localizeString( return ""; } - const currentLocale = locale || navigator.language.split("-")[0] || "fr"; + const currentLocale = locale || getLocale(); if (translatableString[currentLocale]) { return translatableString[currentLocale]; @@ -59,3 +59,47 @@ export function localizeString( return ""; } + +const datetimeFormats: Record< + string, + Record +> = { + fr: { + short: { + year: "numeric", + month: "numeric", + day: "numeric", + }, + text: { + year: "numeric", + month: "long", + day: "numeric", + }, + long: { + year: "numeric", + month: "numeric", + day: "numeric", + hour: "numeric", + minute: "numeric", + hour12: false, + }, + hoursOnly: { + hour: "numeric", + minute: "numeric", + hour12: false, + }, + }, +}; +export function localizeDateTimeFormat( + dateTime: DateTime, + format: keyof typeof datetimeFormats.fr = "short", +): string { + const locale = getLocale(); + const options = + datetimeFormats[locale]?.[format] || datetimeFormats.fr[format]; + return new Intl.DateTimeFormat(locale, options).format( + new Date(dateTime.datetime), + ); +} + +export default datetimeFormats; diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/App.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/App.vue index c1ac025ff..a494cfea8 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/App.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/App.vue @@ -122,7 +122,6 @@ const tabDefinitions: TabDefinition[] = [ ]; const displayedTabs = computed(() => { - // Always show MyCustoms first if present const tabs = [] as TabDefinition[]; for (const tabEnum of homepageConfig.value.displayTabs) { const def = tabDefinitions.find( @@ -137,10 +136,7 @@ const activeTab = ref(Number(HomepageTabs[homepageConfig.value.defaultTab])); const loading = computed(() => store.state.loading); -function selectTab(tab: HomepageTabs) { - if (tab !== HomepageTabs.MyCustoms) { - store.dispatch("getByTab", { tab: tab }); - } +async function selectTab(tab: HomepageTabs) { activeTab.value = tab; } diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/DashboardWidgets/NewsItem.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/DashboardWidgets/NewsItem.vue index 5cbd33712..f98451249 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/DashboardWidgets/NewsItem.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/DashboardWidgets/NewsItem.vue @@ -2,7 +2,9 @@
  • {{ props.item.title }}

    @@ -26,7 +28,9 @@