@cartridge-engine/i18n
    Preparing search index...

    Interface I18nContextValue

    Value provided by LanguageProvider via React context. Accessed via the useI18n hook.

    interface I18nContextValue {
        currentLanguage: string;
        getLanguages: () => string[];
        mergeLanguage: (paths: string[]) => void;
        setDefaultContext: (context?: string) => void;
        setLanguage: (lang: string) => void;
        t: (
            key: string,
            options?: { context?: string; params?: Record<string, string | number> },
        ) => string;
    }
    Index
    currentLanguage: string

    Currently active locale code.

    getLanguages: () => string[]

    Returns all available locale codes.

    mergeLanguage: (paths: string[]) => void

    Merge translation files from one or more directory paths into the current resources. Later paths override earlier paths when the same key exists in multiple sources. Triggers re-render of all consumers.

    Only merges languages whose JSON files exist in the provided paths; other languages are unaffected.

    Type Declaration

      • (paths: string[]): void
      • Parameters

        • paths: string[]

          Array of directory paths, each containing {locale}.json files. Applied in order: later paths win on key conflicts.

        Returns void

    setDefaultContext: (context?: string) => void

    Dynamically update the default context for all t() calls.

    Pass undefined to clear the default context, restoring the original behaviour where only the bare key is looked up.

    setDefaultContext('female');
    // All subsequent t() calls now prefer key.<female> first.

    setDefaultContext(undefined);
    // Back to bare-key-only lookup.
    setLanguage: (lang: string) => void

    Switch to a different language. Triggers re-render of all consumers.

    If the requested language is not available, throws with a message listing available languages.

    t: (
        key: string,
        options?: { context?: string; params?: Record<string, string | number> },
    ) => string

    Translate a key to the current language.

    Dot-separated nested keys are resolved via the flat key map (e.g. menu.title finds the key "menu.title" in the JSON).

    // Simple key
    t('hello') → 'Hello'

    // Parameter interpolation
    t('welcome', { params: { name: 'Alice' } }) → 'Welcome, Alice'

    // Context-based lookup (e.g. gendered forms)
    // Resources: { 'greeting': 'Hello', 'greeting.female': 'Hello, madam' }
    t('greeting', { context: 'female' }) → 'Hello, madam'
    t('greeting', { context: 'unknown' }) → 'Hello' (fallback)

    // Context + interpolation
    // Resources: { 'welcome.female': 'Welcome, Ms. {name}' }
    t('welcome', { context: 'female', params: { name: 'Alice' } }) → 'Welcome, Ms. Alice'

    Missing keys resolve to the key string itself.