AngularJS translate dynamic string
10,352
You must not have the translationProvider configured correctly. You should have something like this in your config:
$translateProvider.translations({
'TRANSLATEME': 'Here is the translation'
});
and data.foo needs to equal TRANSLATEME
.
Here's a Plunker showing it working.
Author by
Jack
Updated on June 04, 2022Comments
-
Jack almost 2 years
I'm using angular-translate module for translation, but i have dynamic string which doesn't get translated.
I have tried this ways:
{{ data.foo | translate }}
This didn't work.
And i tried using his own directive:
<span translate>{{ data.foo }}</span>
Using this method i get in output result of data.foo without translation.
What is the best way to do this?
Thanks :)
-
Barry over 8 yearsHa! For some reason I read your comment as "I get undefined jack"... which was highly amusing for me. @Jack
-
fero about 7 yearsI just found out that something like
<span translate>FOO.BAR.{{ data.foo }}</span>
doesn't work. It has to be<span translate>{{ 'FOO.BAR.' + data.foo }}</span>