Resolves the remaining review threads: - Reset to auto-detect across all three layers (Greptile): store passes language:null through as null-as-delete; dashboard gains an Auto option (clearLanguage + hasExplicitChoice in useLanguage, re-detects from navigator, syncs cross-tab); CLI accepts 'fn settings set language auto'. Catalog keys added for all five locales; tests at every layer. - CLI i18n test singleton: afterEach locale restore so zh-CN/fr switches can't leak across cases (CodeRabbit nitpick) - useLocaleFormat memoized per locale for stable formatter identities (CodeRabbit nitpick) - settings-reference.md documents the auto reset path Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
import { useMemo } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
/**
|
|
* Locale-aware date/number formatting bound to the active i18n locale.
|
|
*
|
|
* Replaces the ~45 `toLocale*(undefined, …)` call sites that previously used
|
|
* the implicit browser locale. Routing them through this hook threads the
|
|
* user's chosen language into all date/number formatting (R8).
|
|
*/
|
|
export function useLocaleFormat() {
|
|
const { i18n } = useTranslation();
|
|
const locale = i18n.resolvedLanguage || i18n.language || "en";
|
|
|
|
// Memoized per locale so the formatter identities stay stable across
|
|
// renders — consumers can safely put them in hook dependency arrays.
|
|
return useMemo(
|
|
() => ({
|
|
locale,
|
|
formatDate: (value: number | string | Date, options?: Intl.DateTimeFormatOptions) =>
|
|
new Date(value).toLocaleDateString(locale, options),
|
|
formatTime: (value: number | string | Date, options?: Intl.DateTimeFormatOptions) =>
|
|
new Date(value).toLocaleTimeString(locale, options),
|
|
formatDateTime: (value: number | string | Date, options?: Intl.DateTimeFormatOptions) =>
|
|
new Date(value).toLocaleString(locale, options),
|
|
formatNumber: (value: number, options?: Intl.NumberFormatOptions) =>
|
|
value.toLocaleString(locale, options),
|
|
}),
|
|
[locale],
|
|
);
|
|
}
|