@sco-techlab/nestjs-i18n v1.0.2
Get Started
- Install dependency
Import Translate module in your 'app.module.ts' file, register or registerAsync methods availables
Module import is global mode, to use trasnalte service only need constructor dependency inyection
Catch your 'accept-language' header request in your interceptor and set your current language
Add your interceptor to your 'app.module.ts' file if you have created it
Nest.JS i18n config
Translate files (JSON)
You should create the translation files with the following format 'language.json' such as 'en.json', 'es.json'... All translation files should be in the same folder, which is the path we configured in the module
- En translates
- Es translates
Translate method
For single translate like 'hello.world' in last translate files example you should pass the label name like argument
For nested translate like 'tests / test1 / 1' you must pass the blocks and translate name in parent order as a string[] value
If the translation does not exist, the method will return as a result the name of the translation passed by parameter to the translate method
Examples
- Live coding: Stackblitz example