Class I18nAbstract

Description

Internationalization library

Example

import { inject, container, Core, Types } from '@biorate/inversion';
import { Config, IConfig } from '@biorate/config';
import { I18n as I18nCommon, t } from '@biorate/i18n';

class I18n extends I18nCommon {
protected options = {
fallbackLng: 'ru',
lng: 'ru',
debug: false,
resources: {
ru: {
translation: {
'Привет мир': 'Привет мир!',
},
},
en: {
translation: {
'Привет мир': 'Hello world!',
},
},
},
};
}

export class Root extends Core() {
@inject(Types.Config) public config: IConfig;
@inject(I18n) public i18n: I18n;
}

container.bind<IConfig>(Types.Config).to(Config).inSingletonScope();
container.bind<I18n>(I18n).toSelf().inSingletonScope();
container.bind<Root>(Root).toSelf().inSingletonScope();

(async () => {
const root = container.get<Root>(Root);
await root.$run();
console.log(t`Привет мир`); // Привет мир!
console.log(t(`Привет мир`, { lng: 'en' })); // Hello world!
})();

Hierarchy

  • I18n

Constructors

Properties

Accessors

Methods

Constructors

Properties

config: IConfig
options: Record<string, unknown>

Accessors

Methods

Generated using TypeDoc