Reputation: 117
I am making an app with multi-language. So, I have 2 different files containing typical key-pair label texts. Now for one situation, depending on an ID obtained from server, I need to hold the id and display a label text. If I am not very clear, please excuse the pseudo that I intend to achieve :-
<td>{{language.{{button.btnId}}}}</td>
Is there any way I can achieve this?
Note I am doing this because some buttons in the application are restricted.
Upvotes: 0
Views: 419
Reputation: 3197
NOTE: not a direct answer to the question, one has already been given but this you might find useful and it does not fit into a comment:
With AngularJS I would use angular-translate to handle i18n in my applications. Tested it several times in very different applications, it's stable and powerful.
https://github.com/angular-translate/angular-translate
You can obtain it via npm also.
They took a lot of consideration when making it, it's nearly a standard, rarely I saw (this is OFC personal experience) serious multilanguage AngularJS app after it came out it without it so I would definitely go with a battle-ready solution instead reinventing the weel.
In this example, angular-translate you would simply use {{ LABELNAME | translate}}
to obtain translation in any template based on the language set in the application. Not only the syntax is better but their recommended way of storing translations in JSON files with labels is miles better than holding it in controllers.
Upvotes: 0
Reputation: 41397
If language
is an object then use like this.
<td>{{ language[button.btnId] }}</td>
Upvotes: 1