Jack
Jack

Reputation: 1521

AngularJS translate dynamic string

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

Upvotes: 3

Views: 10606

Answers (2)

Jerrad
Jerrad

Reputation: 5290

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.

Upvotes: 3

Jscti
Jscti

Reputation: 14440

Do you have a string matching a translation key in data.foo ? is so :

<span translate="{{data.foo}}"></span>

definitely works; as well as :

<span>{{ data.foo | translate}}</span>

Upvotes: 0

Related Questions