fix!: require external date formatter
This commit is contained in:
@@ -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
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user