İçeriğe geç
sern

Localizer

Bu içerik henüz dilinizde mevcut değil.

A localization module for managing translations and providing localized content in your application.

Installation

npm i @sern/localizer

Usage

Initializing the Localizer

1
import { makeDependencies } from '@sern/handler';
2
import { Localization } from '@sern/localizer';
3
4
await makeDependencies(({ add }) => {
5
// add other deps
6
add('localizer', Localization());
7
});

This localizer is FILE BASED. Create the directory assets/locals. Each json file in here must be named after the locale

~/assets/locals/es-ES.json
1
{
2
"salute": {
3
"hello": "hola"
4
}
5
}

Accessing translations

  • If you are in a command execute callback, use deps from SDT.
1
execute : (ctx, { deps }) => {
2
//the localizer object from makeDependencies
3
deps.localizer
4
// Returns the Spanish translation for 'salute.hello'
5
deps.localizer.translate("salute.hello", "es-ES");
6
}
1
import { local } from '@sern/localizer';
2
3
// Returns the Spanish translation for 'salute.hello'
4
const greeting = local('salute.hello', 'es-ES');