My angular controller may generate the messages, that I intent to translate using angular-translations.
In controller I currently assign a variable to translation key, such as:
$scope.info = "core.projectconfig.created";
where that key has its translation specified as
core.projectconfig.created <=> 'Project {{projectName}} created successfully'
As you can see, I also need to substutute projectName in translation.
I tried something like this in my view
<P translate="{{info}}", translate-values="{projectName : projectData.ProjectName}"></p>
but it does not work. How I can translate dynamically-found translation key and also add a scope variable into the translated line?
You can inject $translate directive which is provided by https://github.com/angular-translate/angular-translate in your controller.
Later use $translate like this for dynamic key:
$translate(translation_key)
Scope variables in your message can be used like below:
$translate(translation_key, { scope_variable_key: $scope_value })
e.g:$translate("core.projectconfig.created", { projectName: $scope.projectData. ProjectName })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With