A simple i18n service.
First you need create a json file in locales folder with the locale name, for example, en.json
.
The file content needs to follow the flow structure.
{
"en" : {
"hello" : "hello",
"something": "Some text",
"views" : {
"login" : {
"title": "Login page",
"email": "E-mail",
...
}
}
...
}
}
Your new locale will be available on http://localhost:3000/en
You can have how many locales you want. For example:
http://localhost:3000/en
http://localhost:3000/es
http://localhost:3000/pt
http://localhost:3000/pt-br
You can set the locales folder by environment variable, setting LOCALES_FOLDER=/your/locales/folder/
You can get the literals by three ways.
To get all locale literals you just call the url http://localhost:3000/{locale}/translate
To get a list of literals you need pass the required list by query string, for example: http://localhost:3000/en?l=hello,something
You can get a part of your literal callin the service passing the part by query string, for example:
http://localhost:3000/en?l=views.login
The result will be:
{
"views" : {
"login" : {
"title": "Login page",
"email": "E-mail",
...
}
}
}