I assume you're using ngx-tranlate :
Then you will know that the translations are saved in an object that is created from a JSON, something like:
{
"name": "nombre",
"pantallaLogin": {
"user: "Usuario",
"password": "Contraseña"
},
...
}
So, how does the API work?
The translateService.get('<clave>')
method returns a Observable<string | Object>
:
With the example set, translateService.get('pantallaLogin.user')
would return an observable that when resolved would give you the value "Usuario"
, but with translateService.get('pantallaLogin')
the Observable would be solved with the whole object: { "user: "Usuario", "password": "Contraseña" }
(In both cases I am assuming that the Current language is Spanish, of course).
It also accepts an array of Strings, in which case it will return an object whose entries will be all the keys you have requested:
translateService.get(['pantallaLogin.user','pantallaLogin.password'])
will return an Observable that will be given an object like this:
{ 'pantallaLogin.user':'Usuario','pantallaLogin.password':'Contraseña'}
Above you have the translateService.getTranslation('<lang>');
method
If you pass it as parameter 'es'
, it will return an Observable, which is resolved with the entire file es.json
, that is, all the entries in the Spanish language.