71 lines
2.5 KiB
TypeScript
71 lines
2.5 KiB
TypeScript
import type { InitOptions } from "i18next";
|
|
|
|
export const defaultLocale = "de";
|
|
export const supportedLocales = ["de", "en"];
|
|
export type SupportedLocale = (typeof supportedLocales)[number];
|
|
|
|
// Namespace order:
|
|
// - `translations` is the legacy single-file namespace that still holds the
|
|
// bulk of UI strings. New keys for *new* surfaces should land in a
|
|
// dedicated namespace.
|
|
// - `common` collects shared UI primitives — buttons, generic labels — and
|
|
// ICU-MessageFormat plural patterns (`itemsSelected`, `memberCount`).
|
|
// - `settings`/`billing`/`crm`/`auth`/`emailMarketing` are per-area
|
|
// namespaces split out of the legacy file. See `docs/contributing/i18n.md`.
|
|
export const i18nNamespaces = ["translations", "errors", "mail", "common", "settings", "billing", "crm", "auth", "emailMarketing"] as const;
|
|
export type I18nNamespace = (typeof i18nNamespaces)[number];
|
|
|
|
export const i18nConfig = {
|
|
supportedLngs: supportedLocales,
|
|
fallbackLng: defaultLocale,
|
|
defaultNS: "translations",
|
|
ns: [...i18nNamespaces],
|
|
react: {
|
|
useSuspense: false,
|
|
},
|
|
} satisfies InitOptions;
|
|
|
|
export function isSupportedLocale(locale: string | undefined): locale is SupportedLocale {
|
|
return Boolean(locale && supportedLocales.includes(locale));
|
|
}
|
|
|
|
const ltrLocales = new Set<string>(["de", "en"]);
|
|
const rtlLocales = new Set<string>(["ar", "he", "fa", "ur"]);
|
|
|
|
export type TextDirection = "ltr" | "rtl";
|
|
|
|
export function getDirection(locale: string | undefined): TextDirection {
|
|
if (!locale) return "ltr";
|
|
if (rtlLocales.has(locale)) return "rtl";
|
|
if (ltrLocales.has(locale)) return "ltr";
|
|
return "ltr";
|
|
}
|
|
|
|
export function isRTL(locale: string | undefined): boolean {
|
|
return getDirection(locale) === "rtl";
|
|
}
|
|
|
|
// Foundation extensions (#72 i18n-foundation). Exports are namespaced via
|
|
// `./intl` and `./icu` subpaths in `package.json#exports`, but we also
|
|
// re-export the helpers here so callers can `import { formatCurrency } from
|
|
// "@toolctrl/i18n"` without juggling subpaths.
|
|
|
|
export {
|
|
formatNumber,
|
|
formatPercent,
|
|
formatCompactNumber,
|
|
formatCurrency,
|
|
formatDate,
|
|
formatRelativeTime,
|
|
formatList,
|
|
type FormatNumberOptions,
|
|
type FormatCurrencyOptions,
|
|
type FormatDateOptions,
|
|
type FormatRelativeTimeOptions,
|
|
type FormatListOptions,
|
|
} from "./intl/index.js";
|
|
|
|
export { formatIcu, createIcuFormatter, type IcuValues, type IcuOptions, type IcuFormatter } from "./icu/index.js";
|
|
|
|
export { createUseTranslate, isIcuMessage, type Translator, type ReactI18nextLike, type UseTranslateOptions } from "./useTranslate.js";
|