Additional Functionality
#
Reference Other KeysYou can point to specific keys in other keys from the same translation file. For example:
So the result of service.translate('fromList')
will be: "from home english".
When using this feature inside a scope, make sure you prefix the key reference with the scope name:
So the result of service.translate('admin.fromList')
will be: "from home english".
You can also pass parameters to the reused key. For example:
So the result of service.translate('greet', {name: 'John'})
will be: "Hello John, have a good day!".
Watch out from creating circular referencing! For Example:
translate()
#
You don't have to inject the service each time you need to translate a key. Transloco has an exported translate()
function:
important
Note that this function is a proxy to the TranslocoService.translate method.
It will not work if the service didn't initialize.
In order to safely use this method, you are responsible for ensuring that the translation files have been successfully loaded by the time it's called.
getBrowserLang()
#
Returns the language code name from the browser, e.g. "en"
getBrowserCultureLang()
#
Returns the culture language code name from the browser, e.g. "en-US"