I18n
Handles internationalization and localization (translations, conversions, formatting and such).
constructor
Class constructor.
public constructor(logger: Logger, labels: Labels);
Parameters
- logger: Logging system to use.
- labels: List of available labels for translation.
Usage
const i18n = new I18n(logger, {
MENU: {
TITLE: 'Menu',
FIRST_ITEM: {
LABEL: 'First item'
},
SECOND_ITEM: {
LABEL: 'Second item'
}
}
});
t
Translates label
injecting values from variables
if necessary.
public t(label: string, values?: Record<string, unknown>): string;
Parameters
- label: Label to translate.
- values: Optional list of values to inject in the translated label. Defaults to
{}
.
Returns
Translated label.
Usage
i18n.t('MENU.FIRST_ITEM.LABEL'); // "First item"
numeric
Translates numeric value
.
public numeric(value: number): string;
Parameters
- value: Value to translate.
Returns
Translated value.
Usage
i18n.numeric(123); // "123"
dateTime
Translates date value
.
public dateTime(value: Date): string;
Parameters
- value: Value to translate.
Returns
Translated value.
Usage
i18n.dateTime(new Date('2023-01-01T10:21:00')); // "2023/01/01 10:21"