Skip to main content

QI18n

@quik/i18n


@quik/i18n / QI18n

Class: QI18n

Defined in: i18n/src/QI18n.ts:29

Data store used to load and store languages and translation keys that can be used later in the application through the chosen i18n implementation.

Extends​

  • QObject

Implements​

  • IQI18n

Constructors​

Constructor​

new QI18n(options?): QI18n

Defined in: i18n/src/QI18n.ts:35

Data store constructor.

Parameters​

options?​

Partial<ILanguageStoreOptions> = {}

A list of options used for the store setup.

Returns​

QI18n

Overrides​

QObject.constructor

Accessors​

defaultLanguage​

Get Signature​

get defaultLanguage(): string

Defined in: i18n/src/QI18n.ts:61

Getter of the default language to be used in the i18n implementation.

Returns​

string

Set Signature​

set defaultLanguage(language): void

Defined in: i18n/src/QI18n.ts:68

Setter of the default language to be used in the i18n implementation.

Parameters​
language​

string

Returns​

void

Implementation of​

IQI18n.defaultLanguage


fallbackLanguage​

Get Signature​

get fallbackLanguage(): string

Defined in: i18n/src/QI18n.ts:83

Getter of the fallback language used when there is no translation key defined in the desired language.

Returns​

string

Set Signature​

set fallbackLanguage(language): void

Defined in: i18n/src/QI18n.ts:90

Setter of the fallback language used when there is no translation key defined in the desired language.

Parameters​
language​

string

Returns​

void

Implementation of​

IQI18n.fallbackLanguage


keys​

Get Signature​

get keys(): string[]

Defined in: i18n/src/QI18n.ts:107

A list of registered keys in the application.

Returns​

string[]

Implementation of​

IQI18n.keys


languages​

Get Signature​

get languages(): string[]

Defined in: i18n/src/QI18n.ts:100

A list of supported languages available in the application.

Returns​

string[]

Implementation of​

IQI18n.languages


logger​

Get Signature​

get protected logger(): IQLogger

Defined in: core/src/QObject.ts:15

The logger getter for the object.

Returns​

IQLogger

Inherited from​

QObject.logger


name​

Get Signature​

get name(): string

Defined in: core/src/QObject.ts:8

Returns​

string

Inherited from​

QObject.name


resources​

Get Signature​

get protected resources(): Record<LanguageName, LanguageResources>

Defined in: i18n/src/QI18n.ts:119

Getter for the resource object.

Returns​

Record<LanguageName, LanguageResources>

Methods​

default()​

default(): LanguageResources

Defined in: i18n/src/QI18n.ts:261

Returns the resource object, unflattened, language-based.

Returns​

LanguageResources

Implementation of​

IQI18n.default


dump()​

dump(language?): Record<LanguageName, LanguageResources>

Defined in: i18n/src/QI18n.ts:240

Returns the resource object, unflattened, language-based.

Parameters​

language?​

string

The language for which we want the objects.

Returns​

Record<LanguageName, LanguageResources>

Implementation of​

IQI18n.dump


endSpan()​

protected endSpan(span): void

Defined in: core/src/QObject.ts:35

End a span returned by startSpan.

Parameters​

span​

TelemetrySpan

The span to end.

Returns​

void

Inherited from​

QObject.endSpan


get()​

get(languageOrKey, key?): string

Defined in: i18n/src/QI18n.ts:222

Method used to fetch a translation key value from the resources store.

Parameters​

languageOrKey​

string

The language for which we want to get the translation key, or the key used to fetch the translation value from the default language.

key?​

string

The key used to fetch the translation value.

Returns​

string

Implementation of​

IQI18n.get


load()​

load(language, records): void

Defined in: i18n/src/QI18n.ts:271

Loads a list of translation items into the specified language.

Parameters​

language​

string

The language you want to load into the store.

records​

LanguageResources

The translation items to be loaded.

Returns​

void

Implementation of​

IQI18n.load


loadFolder()​

loadFolder(folder, recursive?): void

Defined in: i18n/src/QI18n.ts:300

Loads all JSON language files from the specified folder.

Parameters​

folder​

string

The folder from which to load the language files.

recursive?​

boolean

Load the json files recursive?

Returns​

void

Implementation of​

IQI18n.loadFolder


read()​

read(language, filePath): void

Defined in: i18n/src/QI18n.ts:284

Reads translation items into a specified language from a given file.

Parameters​

language​

string

The language you want to load into the store.

filePath​

string

The path to the file to be loaded.

Returns​

void

Implementation of​

IQI18n.read


recordSpanError()​

protected recordSpanError(span, err): void

Defined in: core/src/QObject.ts:45

Record an exception on an active span.

Parameters​

span​

TelemetrySpan

The span to record the error on.

err​

unknown

The error to record.

Returns​

void

Inherited from​

QObject.recordSpanError


remove()​

remove(language, key): void

Defined in: i18n/src/QI18n.ts:332

Removes a translation item from the specified language.

Parameters​

language​

string

The language for which you want to remove the translation item from the store.

key​

string

The key you want to delete.

Returns​

void

Implementation of​

IQI18n.remove


set()​

set(language, key, value): void

Defined in: i18n/src/QI18n.ts:350

Updates the translation key in the specified language with the given value.

Parameters​

language​

string

The language for which you want to update the translation item.

key​

string

The key you want to update.

value​

string

The value to be set to the translation item.

Returns​

void

Implementation of​

IQI18n.set


setSpanAttribute()​

protected setSpanAttribute(span, key, value): void

Defined in: core/src/QObject.ts:64

Set a single attribute on an active span.

Parameters​

span​

TelemetrySpan

The span to update.

key​

string

Attribute key.

value​

string | number | boolean

Attribute value.

Returns​

void

Inherited from​

QObject.setSpanAttribute


setup()​

setup(): Promise<void>

Defined in: i18n/src/QI18n.ts:148

Initializes the internal i18next instance and loads resource bundles.

Returns​

Promise<void>

Implementation of​

IQI18n.setup


setupHttpEngine()​

setupHttpEngine(engine, type): void

Defined in: i18n/src/QI18n.ts:129

Wires the i18next middleware to the provided HTTP server instance.

Parameters​

engine​

any

The HTTP server instance.

type​

string

The type of the HTTP engine (express, koa, or fastify).

Returns​

void

Implementation of​

IQI18n.setupHttpEngine


startSpan()​

protected startSpan(spanName, options?): TelemetrySpan

Defined in: core/src/QObject.ts:26

Start a telemetry span for the given operation name. Returns undefined when no telemetry provider is active.

Parameters​

spanName​

string

Name of the span.

options?​

TelemetrySpanOptions

Optional span attributes and kind.

Returns​

TelemetrySpan

Inherited from​

QObject.startSpan


translate()​

translate(key, parameters?, language?): string

Defined in: i18n/src/QI18n.ts:202

Parameters​

key​

string

parameters?​

ObjectLiteral

language?​

string

Returns​

string

Implementation of​

IQI18n.translate


translator()​

translator(language?): IQTranslator

Defined in: i18n/src/QI18n.ts:194

Translates the given key using the configured i18next instance.

Parameters​

language?​

string

Returns​

IQTranslator

Implementation of​

IQI18n.translator


unload()​

unload(language): void

Defined in: i18n/src/QI18n.ts:363

Removes a language from the store.

Parameters​

language​

string

The language you want to unload from the store.

Returns​

void

Implementation of​

IQI18n.unload