UNPKG

@jay-js/system

Version:

A powerful and flexible TypeScript library for UI, state management, lazy loading, routing and managing draggable elements in modern web applications.

40 lines (39 loc) 1.21 kB
import type { AllPaths, GetTypeAtPath } from "../types.js"; /** * Function for accessing internationalized strings with type safety * * @template T - The type of the translation object (derived from translation files) * @returns A translation function that accepts a key and optional data for variable substitution * * @example * // With flat keys (default approach) * type Translations = { * 'Hello': string; * 'Welcome, {{name}}!': string; * 'You have {{count}} messages': string; * }; * * const t = getI18n<Translations>(); * * // Get a translation * const hello = t('Hello'); * * // With variable substitution * const welcome = t('Welcome, {{name}}!', { name: 'User' }); * const messages = t('You have {{count}} messages', { count: 5 }); * * @example * // With nested keys (requires nestedKeys: true in options) * type NestedTranslations = { * greetings: { * hello: string; * welcome: string; * } * }; * * const t = getI18n<NestedTranslations>(); * const hello = t('greetings.hello'); */ export declare function getI18n<T>(): <Path extends AllPaths<T>>(path: Path, data?: Record<string, any>, options?: { default?: string; }) => GetTypeAtPath<T, Path>;