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
1import { makeDependencies } from '@sern/handler';2import { Localization } from '@sern/localizer';3
4await makeDependencies(({ add }) => {5 // add other deps6 add('localizer', Localization());7});
1import type { Logging, CoreDependencies } from '@sern/handler'2import type { Localizer } from '@sern/localizer'3declare global {4 interface Dependencies extends CoreDependencies {5 localizer: Localizer;6 }7}8export {}
This localizer is FILE BASED.
Create the directory assets/locals
. Each json file in here must be named after the locale
1 {2 "salute": {3 "hello": "hola"4 }5 }
1 {2 "salute": {3 "hello": "hello"4 }5 }
Accessing translations
- If you are in a command execute callback, use
deps
from SDT.
1execute : (ctx, { deps }) => {2 //the localizer object from makeDependencies3 deps.localizer4 // Returns the Spanish translation for 'salute.hello'5 deps.localizer.translate("salute.hello", "es-ES");6}
1import { local } from '@sern/localizer';2
3// Returns the Spanish translation for 'salute.hello'4const greeting = local('salute.hello', 'es-ES');