Skip to main content

@nest-boot/i18n

Classes

I18nMiddleware

Defined in: packages/i18n/src/i18n.middleware.ts:12

Implements

  • NestMiddleware

Constructors

Constructor
new I18nMiddleware(options): I18nMiddleware;

Defined in: packages/i18n/src/i18n.middleware.ts:15

Parameters
ParameterType
optionsI18nModuleOptions
Returns

I18nMiddleware

Properties

options
readonly options: I18nModuleOptions;

Defined in: packages/i18n/src/i18n.middleware.ts:16

Methods

use()
use(
req,
res,
next): void;

Defined in: packages/i18n/src/i18n.middleware.ts:24

Parameters
ParameterType
reqRequest
resResponse
next() => void
Returns

void

Implementation of
NestMiddleware.use

I18nModule

Defined in: packages/i18n/src/i18n.module.ts:29

Extends

  • ConfigurableModuleClass

Implements

  • NestModule

Indexable

[key: string]: any

Constructors

Constructor
new I18nModule(): I18nModule;

Defined in: node_modules/.pnpm/@nestjs+common@11.1.9/node_modules/@nestjs/common/module-utils/interfaces/configurable-module-cls.interface.d.ts:12

Returns

I18nModule

Inherited from
ConfigurableModuleClass.constructor

Methods

configure()
configure(consumer): void;

Defined in: packages/i18n/src/i18n.module.ts:72

Parameters
ParameterType
consumerMiddlewareConsumer
Returns

void

Implementation of
NestModule.configure
register()
static register(options): DynamicModule;

Defined in: packages/i18n/src/i18n.module.ts:30

Parameters
ParameterType
optionsI18nModuleOptions & Partial<{ isGlobal: boolean; }>
Returns

DynamicModule

Overrides
ConfigurableModuleClass.register
registerAsync()
static registerAsync(options): DynamicModule;

Defined in: packages/i18n/src/i18n.module.ts:36

Parameters
ParameterType
optionsConfigurableModuleAsyncOptions<I18nModuleOptions, "create"> & Partial<{ isGlobal: boolean; }>
Returns

DynamicModule

Overrides
ConfigurableModuleClass.registerAsync

Interfaces

I18n

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:228

Extends

  • CustomInstanceExtensions

Properties

exists
exists: ExistsFunction;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:275

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

format
format: FormatFunction;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:381

Exposes interpolation.format function added on init.

initializedLanguageOnce
initializedLanguageOnce: boolean;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:521

Language was initialized

initializedStoreOnce
initializedStoreOnce: boolean;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:516

Store was initialized

isInitialized
isInitialized: boolean;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:506

Is initialized

isInitializing
isInitializing: boolean;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:511

Is initializing

language
language: string;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:309

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
languages: readonly string[];

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:314

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

modules
modules: Modules;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:260

List of modules used

options
options: InitOptions;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:501

Current options

resolvedLanguage?
optional resolvedLanguage: string;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:320

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

services
services: Services;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:265

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

store
store: ResourceStore;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:270

Internal container for translation resources

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

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:230

Methods

addResource()
addResource(
lng,
ns,
key,
value,
options?): I18n;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:457

Adds one key/value.

Parameters
ParameterType
lngstring
nsstring
keystring
valuestring
options?{ keySeparator?: string; silent?: boolean; }
options.keySeparator?string
options.silent?boolean
Returns

I18n

addResourceBundle()
addResourceBundle(
lng,
ns,
resources,
deep?,
overwrite?): I18n;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:475

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
ParameterType
lngstring
nsstring
resourcesany
deep?boolean
overwrite?boolean
Returns

I18n

addResources()
addResources(
lng,
ns,
resources): I18n;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:468

Adds multiple key/values.

Parameters
ParameterType
lngstring
nsstring
resourcesany
Returns

I18n

changeLanguage()
changeLanguage(lng?, callback?): Promise<TFunction<"translation", undefined>>;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:303

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
ParameterType
lng?string
callback?Callback
Returns

Promise<TFunction<"translation", undefined>>

cloneInstance()
cloneInstance(options?, callback?): I18n;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:395

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
ParameterType
options?CloneOptions
callback?Callback
Returns

I18n

createInstance()
createInstance(options?, callback?): I18n;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:389

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
ParameterType
options?InitOptions<object>
callback?Callback
Returns

I18n

dir()
dir(lng?): "ltr" | "rtl";

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:376

Returns rtl or ltr depending on languages read direction.

Parameters
ParameterType
lng?string
Returns

"ltr" | "rtl"

emit()
emit(eventName, ...args): void;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:526

Emit event

Parameters
ParameterType
eventNamestring
...argsany[]
Returns

void

getDataByLanguage()
getDataByLanguage(lng): 
| {
[key: string]: {
[key: string]: string;
};
}
| undefined;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:280

Returns a resource data by language.

Parameters
ParameterType
lngstring
Returns

| { [key: string]: { [key: string]: string; }; } | undefined

getFixedT()
getFixedT<Ns, TKPrefix, ActualNs>(...args): TFunction<ActualNs, TKPrefix>;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:289

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
Type Parameter
Ns extends Namespace | null
TKPrefix extends KeyPrefix<Ns>
ActualNs extends Namespace
Parameters
ParameterType
...args| [string | readonly string[], Ns, TKPrefix] | [null, Ns, TKPrefix]
Returns

TFunction<ActualNs, TKPrefix>

getResource()
getResource(
lng,
ns,
key,
options?): any;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:447

Gets one value by given key.

Parameters
ParameterType
lngstring
nsstring
keystring
options?Pick<InitOptions<object>, "keySeparator" | "ignoreJSONStructure">
Returns

any

getResourceBundle()
getResourceBundle(lng, ns): any;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:491

Returns a resource bundle.

Parameters
ParameterType
lngstring
nsstring
Returns

any

hasLoadedNamespace()
hasLoadedNamespace(ns, options?): boolean;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:326

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

Parameters
ParameterTypeDescription
nsstring | readonly string[]-
options?{ fallbackLng?: false | FallbackLng; lng?: string | readonly string[]; precheck?: (i18n, loadNotPending) => boolean | undefined; }-
options.fallbackLng?false | FallbackLng-
options.lng?string | readonly string[]-
options.precheck?(i18n, loadNotPending) => boolean | undefinedif undefined is returned default checks are performed.
Returns

boolean

hasResourceBundle()
hasResourceBundle(lng, ns): boolean;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:486

Checks if a resource bundle exists.

Parameters
ParameterType
lngstring
nsstring
Returns

boolean

init()
Call Signature
init(callback?): Promise<TFunction<"translation", undefined>>;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:244

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
ParameterTypeDescription
callback?Callbackwill be called after all translations were loaded or with an error when failed (in case of using a backend).
Returns

Promise<TFunction<"translation", undefined>>

Call Signature
init<T>(options, callback?): Promise<TFunction<"translation", undefined>>;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:245

Type Parameters
Type Parameter
T
Parameters
ParameterType
optionsInitOptions<T>
callback?Callback
Returns

Promise<TFunction<"translation", undefined>>

loadLanguages()
loadLanguages(lngs, callback?): Promise<void>;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:356

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

Parameters
ParameterType
lngsstring | readonly string[]
callback?Callback
Returns

Promise<void>

loadNamespaces()
loadNamespaces(ns, callback?): Promise<void>;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:351

Loads additional namespaces not defined in init options.

Parameters
ParameterType
nsstring | readonly string[]
callback?Callback
Returns

Promise<void>

loadResources()
loadResources(callback?): void;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:247

Parameters
ParameterType
callback?(err) => void
Returns

void

off()
off(event, listener?): void;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:442

Remove event listener removes all callback when callback not specified

Parameters
ParameterType
eventstring
listener?(...args) => void
Returns

void

on()
Call Signature
on(event, callback): void;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:400

Gets fired after initialization.

Parameters
ParameterType
event"initialized"
callback(options) => void
Returns

void

Call Signature
on(event, callback): void;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:405

Gets fired on loaded resources.

Parameters
ParameterType
event"loaded"
callback(loaded) => void
Returns

void

Call Signature
on(event, callback): void;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:413

Gets fired if loading resources failed.

Parameters
ParameterType
event"failedLoading"
callback(lng, ns, msg) => void
Returns

void

Call Signature
on(event, callback): void;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:418

Gets fired on accessing a key not existing.

Parameters
ParameterType
event"missingKey"
callback(lngs, namespace, key, res) => void
Returns

void

Call Signature
on(event, callback): void;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:426

Gets fired when resources got added or removed.

Parameters
ParameterType
event"added" | "removed"
callback(lng, ns) => void
Returns

void

Call Signature
on(event, callback): void;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:431

Gets fired when changeLanguage got called.

Parameters
ParameterType
event"languageChanged"
callback(lng) => void
Returns

void

Call Signature
on(event, listener): void;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:436

Event listener

Parameters
ParameterType
eventstring
listener(...args) => void
Returns

void

reloadResources()
Call Signature
reloadResources(
lngs?,
ns?,
callback?): Promise<void>;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:361

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
ParameterType
lngs?string | readonly string[]
ns?string | readonly string[]
callback?() => void
Returns

Promise<void>

Call Signature
reloadResources(
lngs,
ns,
callback?): Promise<void>;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:366

Parameters
ParameterType
lngsnull
nsstring | readonly string[]
callback?() => void
Returns

Promise<void>

removeResourceBundle()
removeResourceBundle(lng, ns): I18n;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:496

Removes an existing bundle.

Parameters
ParameterType
lngstring
nsstring
Returns

I18n

setDefaultNamespace()
setDefaultNamespace(ns): void;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:371

Changes the default namespace.

Parameters
ParameterType
nsstring
Returns

void

use()
use<T>(module): this;

Defined in: node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/index.d.ts:255

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
Type Parameter
T extends Module
Parameters
ParameterTypeDescription
moduleT | NewableModule<T> | Newable<T>Accepts a class or object
Returns

this

Variables

I18N

const I18N: typeof I18N;

Defined in: packages/i18n/src/i18n.constants.ts:1


t()

const t: (key, options?) => string = translation;

Defined in: packages/i18n/src/utils/translation.ts:19

Parameters

ParameterType
keystring | string[]
options?TOptions

Returns

string

Functions

InjectI18n()

function InjectI18n(): PropertyDecorator & ParameterDecorator;

Defined in: packages/i18n/src/decorators/inject-i18n.decorator.ts:5

Returns

PropertyDecorator & ParameterDecorator


translation()

function translation(key, options?): string;

Defined in: packages/i18n/src/utils/translation.ts:6

Parameters

ParameterType
keystring | string[]
options?TOptions

Returns

string