14 lines
656 B
TypeScript
14 lines
656 B
TypeScript
import { en } from "./en.ts";
|
|
import { kk } from "./kk.ts";
|
|
import { ru, type Dict } from "./ru.ts";
|
|
|
|
export type { Dict };
|
|
export const LANGS = { ru, kk, en } as const;
|
|
export type Lang = keyof typeof LANGS;
|
|
export const LANG_NAMES: Record<Lang, string> = { ru: "Русский", kk: "Қазақша", en: "English" };
|
|
export const isLang = (v: unknown): v is Lang => typeof v === "string" && Object.hasOwn(LANGS, v);
|
|
|
|
/** Подставляет {ключ} в строку перевода. */
|
|
export const fmt = (s: string, vars: Record<string, string | number>): string =>
|
|
s.replace(/\{(\w+)\}/g, (m, k: string) => (k in vars ? String(vars[k]) : m));
|