Interface i18n

Hierarchy

  • i18n

Properties

exists: ExistsFunction<string, $Dictionary>

Uses similar args as the t function and returns true if a key exists.

Exposes interpolation.format function added on init.

isInitialized: boolean

Is initialized

language: string

Is set to the current detected or set language. If you need the primary used language depending on your configuration (supportedLngs, load) you will prefer using i18next.languages[0].

languages: readonly string[]

Is set to an array of language-codes that will be used it order to lookup the translation value.

modules: Modules

List of modules used

options: InitOptions<object>

Current options

resolvedLanguage?: string

Is set to the current resolved language. It can be used as primary used language, for example in a language switcher.

services: Services

Internal container for all used plugins and implementation details like languageUtils, pluralResolvers, etc.

Internal container for translation resources

t: TFunction<["translation", ...string[]], undefined>

Methods

  • Adds one key/value.

    Parameters

    • lng: string
    • ns: string
    • key: string
    • value: string
    • Optional options: {
          keySeparator?: string;
          silent?: boolean;
      }
      Optional
      • Optional keySeparator?: string
      • Optional silent?: boolean

    Returns i18n

  • Adds a complete bundle. Setting deep param to true will extend existing translations in that file. Setting overwrite to true it will overwrite existing translations in that file.

    Parameters

    • lng: string
    • ns: string
    • resources: any
    • Optional deep: boolean
      Optional
    • Optional overwrite: boolean
      Optional

    Returns i18n

  • Adds multiple key/values.

    Parameters

    • lng: string
    • ns: string
    • resources: any

    Returns i18n

  • Changes the language. The callback will be called as soon translations were loaded or an error occurs while loading. HINT: For easy testing - setting lng to 'cimode' will set t function to always return the key.

    Parameters

    • Optional lng: string
      Optional
    • Optional callback: Callback
      Optional

    Returns Promise<TFunction<"translation", undefined>>

  • Creates a clone of the current instance. Shares store, plugins and initial configuration. Can be used to create an instance sharing storage but being independent on set language or namespaces.

    Parameters

    Returns i18n

  • Will return a new i18next instance. Please read the options page for details on configuration options. Providing a callback will automatically call init. The callback will be called after all translations were loaded or with an error when failed (in case of using a backend).

    Parameters

    Returns i18n

  • Returns rtl or ltr depending on languages read direction.

    Parameters

    • Optional lng: string
      Optional

    Returns "ltr" | "rtl"

  • Emit event

    Parameters

    • eventName: string
    • Rest ...args: any[]
      Rest

    Returns void

  • Returns a resource data by language.

    Parameters

    • lng: string

    Returns {
        [key: string]: {
            [key: string]: string;
        };
    }

    • [key: string]: {
          [key: string]: string;
      }
      • [key: string]: string
  • Returns a t function that defaults to given language or namespace. Both params could be arrays of languages or namespaces and will be treated as fallbacks in that case. On the returned function you can like in the t function override the languages or namespaces by passing them in options or by prepending namespace.

    Accepts optional keyPrefix that will be automatically applied to returned t function.

    Type Parameters

    • Ns extends Namespace = "translation"

    • TKPrefix extends string = undefined

    • ActualNs extends Namespace = Ns extends null
          ? "translation"
          : Ns

    Parameters

    • Rest ...args: [lng: string | readonly string[], ns?: Ns, keyPrefix?: TKPrefix] | [lng: null, ns: Ns, keyPrefix?: TKPrefix]
      Rest

    Returns TFunction<ActualNs, TKPrefix>

  • Gets one value by given key.

    Parameters

    • lng: string
    • ns: string
    • key: string
    • Optional options: Pick<InitOptions<object>, "keySeparator" | "ignoreJSONStructure">
      Optional

    Returns any

  • Returns a resource bundle.

    Parameters

    • lng: string
    • ns: string

    Returns any

  • Checks if namespace has loaded yet. i.e. used by react-i18next

    Parameters

    • ns: string | readonly string[]
    • Optional options: {
          lng?: string | readonly string[];
          precheck: ((i18n, loadNotPending) => boolean);
      }
      Optional
      • Optional lng?: string | readonly string[]
      • precheck: ((i18n, loadNotPending) => boolean)
          • (i18n, loadNotPending): boolean
          • Parameters

            • i18n: i18n
            • loadNotPending: ((lng, ns) => boolean)
                • (lng, ns): boolean
                • Parameters

                  • lng: string | readonly string[]
                  • ns: string | readonly string[]

                  Returns boolean

            Returns boolean

    Returns boolean

  • Checks if a namespace has been loaded.

    Parameters

    • ns: string
    • Optional options: Pick<InitOptions<object>, "fallbackLng">
      Optional

    Returns boolean

  • Checks if a resource bundle exists.

    Parameters

    • lng: string
    • ns: string

    Returns boolean

  • The default of the i18next module is an i18next instance ready to be initialized by calling init. You can create additional instances using the createInstance function.

    Parameters

    • Optional callback: Callback

      will be called after all translations were loaded or with an error when failed (in case of using a backend).

      Optional

    Returns Promise<TFunction<"translation", undefined>>

  • Type Parameters

    • T

    Parameters

    Returns Promise<TFunction<"translation", undefined>>

  • Loads additional languages not defined in init options (preload).

    Parameters

    • lngs: string | readonly string[]
    • Optional callback: Callback
      Optional

    Returns Promise<void>

  • Loads additional namespaces not defined in init options.

    Parameters

    • ns: string | readonly string[]
    • Optional callback: Callback
      Optional

    Returns Promise<void>

  • Parameters

    • Optional callback: ((err) => void)
      Optional
        • (err): void
        • Parameters

          • err: any

          Returns void

    Returns void

  • Remove event listener removes all callback when callback not specified

    Parameters

    • event: string
    • Optional listener: ((...args) => void)
      Optional
        • (...args): void
        • Parameters

          • Rest ...args: any[]
            Rest

          Returns void

    Returns void

  • Gets fired after initialization.

    Parameters

    • event: "initialized"
    • callback: ((options) => void)
        • (options): void
        • Parameters

          Returns void

    Returns void

  • Gets fired on loaded resources.

    Parameters

    • event: "loaded"
    • callback: ((loaded) => void)
        • (loaded): void
        • Parameters

          • loaded: {
                [language: string]: {
                    [namespace: string]: boolean;
                };
            }
            • [language: string]: {
                  [namespace: string]: boolean;
              }
              • [namespace: string]: boolean

          Returns void

    Returns void

  • Gets fired if loading resources failed.

    Parameters

    • event: "failedLoading"
    • callback: ((lng, ns, msg) => void)
        • (lng, ns, msg): void
        • Parameters

          • lng: string
          • ns: string
          • msg: string

          Returns void

    Returns void

  • Gets fired on accessing a key not existing.

    Parameters

    • event: "missingKey"
    • callback: ((lngs, namespace, key, res) => void)
        • (lngs, namespace, key, res): void
        • Parameters

          • lngs: readonly string[]
          • namespace: string
          • key: string
          • res: string

          Returns void

    Returns void

  • Gets fired when resources got added or removed.

    Parameters

    • event: "added" | "removed"
    • callback: ((lng, ns) => void)
        • (lng, ns): void
        • Parameters

          • lng: string
          • ns: string

          Returns void

    Returns void

  • Gets fired when changeLanguage got called.

    Parameters

    • event: "languageChanged"
    • callback: ((lng) => void)
        • (lng): void
        • Parameters

          • lng: string

          Returns void

    Returns void

  • Event listener

    Parameters

    • event: string
    • listener: ((...args) => void)
        • (...args): void
        • Parameters

          • Rest ...args: any[]
            Rest

          Returns void

    Returns void

  • Reloads resources on given state. Optionally you can pass an array of languages and namespaces as params if you don't want to reload all.

    Parameters

    • Optional lngs: string | readonly string[]
      Optional
    • Optional ns: string | readonly string[]
      Optional
    • Optional callback: (() => void)
      Optional
        • (): void
        • Returns void

    Returns Promise<void>

  • Parameters

    • lngs: null
    • ns: string | readonly string[]
    • Optional callback: (() => void)
      Optional
        • (): void
        • Returns void

    Returns Promise<void>

  • Removes an existing bundle.

    Parameters

    • lng: string
    • ns: string

    Returns i18n

  • Changes the default namespace.

    Parameters

    • ns: string

    Returns void

  • The use function is there to load additional plugins to i18next. For available module see the plugins page and don't forget to read the documentation of the plugin.

    Type Parameters

    Parameters

    Returns i18n

Generated using TypeDoc