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?

3
  • Is projectData defined on your scope? Do you get any errors? Commented Mar 12, 2014 at 11:08
  • @PascalPrecht, glad to have author here. :) Could you please confirm that my syntax is correct and should work? Then it means that other part of translation, that someone else coded, is not used as it should. Commented Mar 12, 2014 at 13:30
  • 2
    Yes syntax looks good. Commented Mar 12, 2014 at 15:10

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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 <ion-slide ion-slide-tab-label="{{'hpgT3' | translate }}" >

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.