Key Referencing
Last updated
Was this helpful?
You can reference specific keys within other keys in the same translation file. This feature allows for dynamic translations, where one key can depend on another.
Example:
{
"alert": "alert {{value}} english",
"home": "home english",
"fromList": "from {{home}}"
}In this case, calling service.translate('fromList') will return:
"from home english".
When using key references inside a scope, be sure to prefix the referenced key with the scope name.
Example:
{
"alert": "alert {{value}} english",
"home": "home english",
"fromList": "from {{admin.home}}"
}Here, calling service.translate('admin.fromList') will return:
"from home english".
You can also pass parameters to the reused key. This allows you to dynamically insert values into the translation.
Example:
In this case, calling service.translate('greet', {name: 'John'}) will return:
"Hello John, have a good day!".
Be cautious when creating key references that may result in circular references. This can lead to infinite loops and unexpected behavior.
Example:
This will create a circular reference, which should be avoided.
Last updated
Was this helpful?
Was this helpful?
{
"hello": "Hello {{name}},",
"greet": "{{hello}}, have a good day!"
}{
"key": "{{key2}}",
"key2": "{{key}}"
}
