fix!: require external date formatter

This commit is contained in:
Lukas Obermann
2026-03-12 23:14:49 +01:00
parent dfe4234edf
commit 9cdf694437
5 changed files with 15 additions and 14 deletions
+2
View File
@@ -67,11 +67,13 @@ const unitListFormat = new Intl.ListFormat(localeId, {
})
const collator = new Intl.Collator(localeId, { usage: "sort" })
const dateFormatter = new Intl.DateTimeFormat(localeId)
const localeEnv: LocaleEnvironment = {
id: localeId,
format: (text, args) => new MessageFormat(localeId, text, { bidiIsolation: "none" }).format(args),
compare: collator.compare.bind(collator),
formatDate: dateFormatter.format.bind(dateFormatter),
translate: (key, ...rest) =>
new MessageFormat(localeId, localeInstance.translations?.[key] ?? key, {
bidiIsolation: "none",
+1 -1
View File
@@ -114,7 +114,7 @@ export const createEntityDescriptionCreator =
...rawEntry,
body: rawEntry.body.filter(isNotNullish).map(mapRawSection),
errata: rawEntry.errata?.map(({ date, description }) => ({
date: date.toLocaleDateString(locale.id),
date: locale.formatDate(date),
description: description.trim(),
})),
references:
+1
View File
@@ -13,6 +13,7 @@ export type LocaleJoinType = "conjunction" | "disjunction" | "unit"
export type LocaleEnvironment = {
id: string
format: Format
formatDate: (date: Date) => string
translate: Translate
translateMap: TranslateMap
compare: LocaleCompare
+2 -1
View File
@@ -1,6 +1,6 @@
import { assertExhaustive } from "@elyukai/utils/typeSafety"
import { LocaleEnvironment } from "../../src/helpers/locale.js"
import { formatMock, translateMapMock, translateMock } from "./translate.js"
import { formatDateMock, formatMock, translateMapMock, translateMock } from "./translate.js"
const localeId = "en-US"
@@ -22,6 +22,7 @@ const unitListFormat = new Intl.ListFormat(localeId, {
export const defaultLocaleEnvironment: LocaleEnvironment = {
id: "en-US",
format: formatMock,
formatDate: formatDateMock,
translate: translateMock,
translateMap: translateMapMock,
compare: (x, y) => collator.compare(x, y),
+9 -12
View File
@@ -1,26 +1,23 @@
import { MessageFormat } from "messageformat"
import {
Translate,
TranslateMap,
type Format,
} from "../../src/helpers/translate.js"
import { Translate, TranslateMap, type Format } from "../../src/helpers/translate.js"
/**
* A mocked format function.
*/
export const formatMock: Format = (text, args) =>
new MessageFormat("en", text).format(args)
export const formatMock: Format = (text, args) => new MessageFormat("en", text).format(args)
/**
* A mocked date format function that formats a date as YYYY-MM-DD.
*/
export const formatDateMock = (date: Date): string => date.toISOString().split("T")[0] ?? ""
/**
* A mocked translate function.
*/
export const translateMock: Translate = (key, ...rest) =>
new MessageFormat("en", key).format(
rest[0] as Record<string, unknown> | undefined,
)
new MessageFormat("en", key).format(rest[0] as Record<string, unknown> | undefined)
/**
* A mocked translate map function.
*/
export const translateMapMock: TranslateMap = map =>
map?.["en-US"] ?? map?.["de-DE"]
export const translateMapMock: TranslateMap = map => map?.["en-US"] ?? map?.["de-DE"]