Skip to main content

Class: InternationalizationHandler

A generalized class for handling i18next JSON files and their discovery.

Since

1.0.0

Constructors

new InternationalizationHandler()

new InternationalizationHandler(options?: InternationalizationOptions): InternationalizationHandler

Parameters

ParameterTypeDescription
options?InternationalizationOptionsThe options that i18next, @skyra/i18next-backend, and InternationalizationHandler should use.

Returns

InternationalizationHandler

Since

1.0.0

Defined in

projects/plugins/packages/i18next/src/lib/InternationalizationHandler.ts:69

Properties

backendOptions

protected readonly backendOptions: Options<object>

The backend options for @skyra/i18next-backend used by i18next.

Since

1.0.0

Defined in

projects/plugins/packages/i18next/src/lib/InternationalizationHandler.ts:62


fetchLanguage()

fetchLanguage: (context: InternationalizationContext) => Awaitable<null | string>

Parameters

ParameterType
contextInternationalizationContext

Returns

Awaitable<null | string>

A string for the desired language or null for no match.

Defined in

projects/plugins/packages/i18next/src/lib/InternationalizationHandler.ts:131


languages

readonly languages: Map<string, TFunction<"translation", undefined>>

A Map of i18next language functions keyed by their language code.

Since

1.0.0

Defined in

projects/plugins/packages/i18next/src/lib/InternationalizationHandler.ts:43


languagesDirectory

readonly languagesDirectory: string

The director passed to @skyra/i18next-backend. Also used in InternationalizationHandler.walkLanguageDirectory.

Since

1.2.0

Defined in

projects/plugins/packages/i18next/src/lib/InternationalizationHandler.ts:56


languagesLoaded

languagesLoaded: boolean = false

Describes whether InternationalizationHandler.init has been run and languages are loaded in InternationalizationHandler.languages.

Since

1.0.0

Defined in

projects/plugins/packages/i18next/src/lib/InternationalizationHandler.ts:31


namespaces

namespaces: Set<string>

A Set of initially loaded namespaces.

Since

1.2.0

Defined in

projects/plugins/packages/i18next/src/lib/InternationalizationHandler.ts:37


options

readonly options: InternationalizationOptions

The options InternationalizationHandler was initialized with in the client.

Since

1.0.0

Defined in

projects/plugins/packages/i18next/src/lib/InternationalizationHandler.ts:49

Methods

format()

Localizes a content given one or more keys and i18next options.

Since

2.0.0

Param

The language to be used.

Remark

This function also has additional parameters for key, defaultValue, and options, however TSDoc does not let us document those while matching proper implementation. See the overloads for this method for the documentation on those parameters.

See

https://www.i18next.com/overview/api#t

format(locale, key, options)

format<Key, TOpt, Ns, Ret, ActualOptions>(locale: string, key: Key | Key[], options?: ActualOptions): TFunctionReturnOptionalDetails<Ret, TOpt>

Localizes a content given one or more keys and i18next options.

Type Parameters
Type ParameterDefault type
Key extends string-
TOpt extends TOptionsTOptions
Ns extends Namespace"translation"
Ret extends string | $SpecialObjectTOpt["returnObjects"] extends true ? $SpecialObject : string
ActualOptions extends TOptionsBase & $DictionaryTOpt & InterpolationMap<Ret>
Parameters
ParameterTypeDescription
localestringThe language to be used.
keyKey | Key[]The key or keys to retrieve the content from.
options?ActualOptionsThe interpolation options.
Returns

TFunctionReturnOptionalDetails<Ret, TOpt>

The localized content.

The localized content.

Since

2.0.0

Param

The language to be used.

Remark

This function also has additional parameters for key, defaultValue, and options, however TSDoc does not let us document those while matching proper implementation. See the overloads for this method for the documentation on those parameters.

See

https://www.i18next.com/overview/api#t

Since

2.0.0

See

https://www.i18next.com/overview/api#t

Defined in

projects/plugins/packages/i18next/src/lib/InternationalizationHandler.ts:197

format(locale, key, options)

format<Key, TOpt, Ns, Ret, ActualOptions>(locale: string, key: string | string[], options: TOpt & $Dictionary & object): TFunctionReturnOptionalDetails<Ret, TOpt>

Localizes a content given one or more keys and i18next options.

Type Parameters
Type ParameterDefault type
Key extends string-
TOpt extends TOptionsTOptions
Ns extends Namespace"translation"
Ret extends string | $SpecialObjectTOpt["returnObjects"] extends true ? $SpecialObject : string
ActualOptions extends TOptionsBase & $DictionaryTOpt & InterpolationMap<Ret>
Parameters
ParameterTypeDescription
localestringThe language to be used.
keystring | string[]The key or keys to retrieve the content from.
optionsTOpt & $Dictionary & objectThe interpolation options as well as a defaultValue for the key and any key/value pairs.
Returns

TFunctionReturnOptionalDetails<Ret, TOpt>

The localized content.

The localized content.

Since

2.0.0

Param

The language to be used.

Remark

This function also has additional parameters for key, defaultValue, and options, however TSDoc does not let us document those while matching proper implementation. See the overloads for this method for the documentation on those parameters.

See

https://www.i18next.com/overview/api#t

Since

2.0.0

See

https://www.i18next.com/overview/api#t

Defined in

projects/plugins/packages/i18next/src/lib/InternationalizationHandler.ts:214

format(locale, key, defaultValue, options)

format<Key, TOpt, Ns, Ret, ActualOptions>(locale: string, key: string | string[], defaultValue: undefined | string, options?: TOpt & $Dictionary): TFunctionReturnOptionalDetails<Ret, TOpt>

Localizes a content given one or more keys and i18next options.

Type Parameters
Type ParameterDefault type
Key extends string-
TOpt extends TOptionsTOptions
Ns extends Namespace"translation"
Ret extends string | $SpecialObjectTOpt["returnObjects"] extends true ? $SpecialObject : string
ActualOptions extends TOptionsBase & $DictionaryTOpt & InterpolationMap<Ret>
Parameters
ParameterTypeDescription
localestringThe language to be used.
keystring | string[]The key or keys to retrieve the content from.
defaultValueundefined | stringThe default value to use if the key is not found.
options?TOpt & $DictionaryThe interpolation options.
Returns

TFunctionReturnOptionalDetails<Ret, TOpt>

The localized content.

The localized content.

Since

2.0.0

Param

The language to be used.

Remark

This function also has additional parameters for key, defaultValue, and options, however TSDoc does not let us document those while matching proper implementation. See the overloads for this method for the documentation on those parameters.

See

https://www.i18next.com/overview/api#t

Since

2.0.0

See

https://www.i18next.com/overview/api#t

Defined in

projects/plugins/packages/i18next/src/lib/InternationalizationHandler.ts:232


getT()

getT(locale: string): TFunction<"translation", undefined>

Retrieve a raw TFunction from the passed locale.

Parameters

ParameterTypeDescription
localestringThe language to be used.

Returns

TFunction<"translation", undefined>

Since

1.0.0

Defined in

projects/plugins/packages/i18next/src/lib/InternationalizationHandler.ts:180


init()

init(): Promise<void>

Initializes the handler by loading in the namespaces, passing the data to i18next, and filling in the InternationalizationHandler#languages.

Returns

Promise<void>

Since

1.0.0

Defined in

projects/plugins/packages/i18next/src/lib/InternationalizationHandler.ts:137


reloadResources()

reloadResources(): Promise<void>

Returns

Promise<void>

Defined in

projects/plugins/packages/i18next/src/lib/InternationalizationHandler.ts:309


walkRootDirectory()

walkRootDirectory(directory: PathLike): Promise<object>

Parameters

ParameterTypeDescription
directoryPathLikeThe directory that should be walked.

Returns

Promise<object>

languages

languages: string[]

namespaces

namespaces: string[]

Since

3.0.0

Defined in

projects/plugins/packages/i18next/src/lib/InternationalizationHandler.ts:289