Files
OpenFlare/frontend/i18n/runtime.ts
T
2026-10-25 22:35:32 +03:00

21 lines
765 B
TypeScript

'use client';
import type { useTranslations } from 'next-intl';
import { resolveClientLocale } from './client';
import { getRuntimeTranslator, type RuntimeKey } from './runtime-translators';
export { getRuntimeTranslator } from './runtime-translators';
export type RuntimeTranslator = ReturnType<typeof useTranslations>;
// Imperative browser code (network errors, form utilities) has no React hook
// context. Resolve the current preference when creating a message, not at import.
export const runtimeText = Object.assign(
(key: RuntimeKey, values?: Record<string, string | number>) =>
getRuntimeTranslator(resolveClientLocale())(key, values),
{
raw: (key: RuntimeKey): string =>
getRuntimeTranslator(resolveClientLocale()).raw(key),
},
);