Translations: display translation for dynamically found translation key
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 })
eg: $translate("core.projectconfig.created", { projectName: $scope.projectData. ProjectName })
上一篇: 功能对齐在现代处理器上究竟有多重要?
下一篇: 翻译:显示翻译为动态找到的翻译密钥