feat: wire i18n services and shared UI

This commit is contained in:
poyrazavsever
2026-07-19 03:06:56 +03:00
parent 805beccf95
commit 826410f53e
11 changed files with 1330 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
import {
createTranslatorFromMessages,
type I18nNamespace,
type TranslationValues,
} from "../../lib/i18n";
import { getCatalogVersion, getResolvedCatalog } from "./catalog";
export type ServerTranslator = {
locale: string;
fallbackChain: string[];
messages: Record<string, string>;
t: (key: string, values?: TranslationValues) => string;
};
export function createTranslator(
locale: string,
namespaces: readonly I18nNamespace[],
): ServerTranslator {
const catalog = getResolvedCatalog(locale, namespaces, getCatalogVersion());
const translator = createTranslatorFromMessages(catalog.locale, catalog.messages);
return {
locale: catalog.locale,
fallbackChain: catalog.fallbackChain,
messages: catalog.messages,
t(key, values) {
const value = translator.t(key, values);
if (value === key && process.env.NODE_ENV !== "production") {
console.warn(`[i18n] Missing translation key "${key}" for locale "${catalog.locale}".`);
}
return value;
},
};
}
export function getClientI18nPayload(locale: string, namespaces: readonly I18nNamespace[]) {
const catalog = getResolvedCatalog(locale, namespaces, getCatalogVersion());
return {
locale: catalog.locale,
messages: catalog.messages,
};
}