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.

Share:
10,352
Jack
Author by

Jack

Updated on June 04, 2022

Comments

  • Jack
    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
    Barry over 8 years
    Ha! For some reason I read your comment as "I get undefined jack"... which was highly amusing for me. @Jack
  • fero
    fero about 7 years
    I 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>