Auth0 Universal Components
    Preparing search index...

    Variable I18nUtilsConst

    I18nUtils: {
        COMPONENT_REGEX: RegExp;
        VAR_REGEX: RegExp;
        createEnhancedTranslator(
            namespace: string,
            translations: LangTranslations | null,
            overrides?: Record<string, unknown>,
        ): TranslationFunction & {
            trans: (
                key: string,
                options?: {
                    components?: TranslationElements;
                    fallback?: string;
                    vars?: Record<string, unknown>;
                },
            ) => unknown[];
        };
        createTranslator(
            namespace: string,
            translations: LangTranslations | null,
            overrides?: Record<string, unknown>,
        ): TranslationFunction;
        getNestedValue(obj: Record<string, unknown>, path: string): unknown;
        loadTranslations(
            language: string,
            cache?: Map<string, LangTranslations | null>,
        ): Promise<LangTranslations | null>;
        loadTranslationsWithFallback(
            currentLanguage: string,
            fallbackLanguage?: string,
            cache?: Map<string, LangTranslations | null>,
        ): Promise<LangTranslations | null>;
        parseComponents(
            template: string,
            components?: TranslationElements,
        ): unknown[];
        substitute(template: string, vars?: Record<string, unknown>): string;
    } = ...

    Pure utility functions for internationalization (i18n) functionality. These functions handle translation loading, variable substitution, and namespace-based translation.

    Type Declaration

    • COMPONENT_REGEX: RegExp

      Regular expression for matching component placeholders in translation strings. Matches patterns like <0>text</0> or text for safe HTML rendering.

    • VAR_REGEX: RegExp

      Regular expression for matching variable placeholders in translation strings. Matches patterns like ${variableName} for dynamic content substitution.

    • createEnhancedTranslator: function
      • Creates an enhanced translation function that supports both simple translations and component-based translations for safe HTML rendering.

        Parameters

        • namespace: string

          The namespace prefix for translations

        • translations: LangTranslations | null

          The loaded translation data

        • Optionaloverrides: Record<string, unknown>

          Optional override translations that take precedence

        Returns TranslationFunction & {
            trans: (
                key: string,
                options?: {
                    components?: TranslationElements;
                    fallback?: string;
                    vars?: Record<string, unknown>;
                },
            ) => unknown[];
        }

        An enhanced translation function with Trans component support

    • createTranslator: function
      • Creates a translation function for a specific namespace with optional overrides.

        Parameters

        • namespace: string

          The namespace prefix for translations (e.g., 'mfa', 'common')

        • translations: LangTranslations | null

          The loaded translation data

        • Optionaloverrides: Record<string, unknown>

          Optional override translations that take precedence

        Returns TranslationFunction

        A translation function scoped to the specified namespace

    • getNestedValue: function
      • Retrieves a nested value from an object using dot notation path traversal.

        Parameters

        • obj: Record<string, unknown>

          The object to traverse

        • path: string

          Dot-separated path to the desired value (e.g., 'common.errors.required')

        Returns unknown

        The value at the specified path, or undefined if not found

        const obj = { common: { errors: { required: 'Field is required' } } };
        getNestedValue(obj, 'common.errors.required') // Returns: 'Field is required'
    • loadTranslations: function
      • Loads translation data for a specific language from the translations directory.

        Parameters

        • language: string

          The language code to load (e.g., 'en-US', 'es-ES')

        • Optionalcache: Map<string, LangTranslations | null>

          Optional cache map to store loaded translations

        Returns Promise<LangTranslations | null>

        Promise resolving to translation data or null if not found

    • loadTranslationsWithFallback: function
      • Loads translations with automatic fallback support for missing languages.

        Parameters

        • currentLanguage: string

          The primary language to load

        • OptionalfallbackLanguage: string

          Optional fallback language if primary fails

        • Optionalcache: Map<string, LangTranslations | null>

          Optional cache map to store loaded translations

        Returns Promise<LangTranslations | null>

        Promise resolving to translation data with fallback support

    • parseComponents: function
      • Parses a translation string with component placeholders and returns structured data for safe rendering without dangerouslySetInnerHTML.

        Parameters

        • template: string

          The translation string with component placeholders like <0>text</0>

        • Optionalcomponents: TranslationElements

          Object mapping component keys to React elements or render functions

        Returns unknown[]

        Array of strings and React elements for safe rendering

        const result = parseComponents(
        'Click <link>here</link> to learn more',
        { link: (children) => <a href="/help">{children}</a> }
        );
        // Returns: ['Click ', <a href="/help">here</a>, ' to learn more']
    • substitute: function
      • Performs variable substitution in a template string using provided variables.

        Parameters

        • template: string

          The template string containing ${variable} placeholders

        • Optionalvars: Record<string, unknown>

          Object containing variable values for substitution

        Returns string

        The template string with variables substituted

        substitute('Hello ${name}!', { name: 'World' }) // Returns: 'Hello World!'
        substitute('No variables here', { name: 'World' }) // Returns: 'No variables here'