mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-01 19:09:45 +00:00
FIX des bugs du merge request 884
This commit is contained in:
@@ -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<string, Intl.DateTimeFormatOptions>
|
||||
> = {
|
||||
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;
|
||||
|
Reference in New Issue
Block a user