7

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?

onkami
  • 8,791
  • 17
  • 90
  • 176

1 Answers1

3

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 })

Monika
  • 81
  • 7
  • Hello Monika, please help me my below ionic slide label will not translating when i switch the language but it will work fine when i closing and again opening application it will translated but not at a time – KAUSHAL J. SATHWARA Aug 03 '16 at 08:26