0

Ng2-translate directive is causing me some issues, but I don't get if I'm doing something wrong or if it's a bug.

On the same component's html template, the translate pipe is working, while the translate directive is not.

In particular:

<span translate>{{ feature.linkTxt }}</span> // works

<span [translate]="feature.linkTxt"></span> // not working

see https://github.com/ocombe/ng2-translate#4-use-the-service-the-pipe-or-the-directive

Am I missing something or should it work?

EDIT

The variable feature.linkTxt points to the string LEARNMORE, which corresponds to the following json string:

"LEARNMORE": "Learn more",

If I switch from the directive to the pipe, with the same variable, the translated text is displayed.

The feature.linkTxt variable is generated by the following *ngFor statement:

<li *ngFor="let feature of featureslist"> ...
don
  • 4,113
  • 13
  • 45
  • 70

2 Answers2

0

As per ng2-translate example if your language file is as below :

{
  HELLO: 'hello {{value}}'
}

Then you should use it like :

// there is single quote foe HELLO inside [translate]
<div [translate]="'HELLO'" [translateParams]="{value: 'world'}"></div>

So i think your json is like : { feature : { linkTxt : 'Your Text' } } and for it you should use it like :

<span [translate]="'feature.linkTxt'"></span>
ranakrunal9
  • 13,320
  • 3
  • 42
  • 43
  • In my case `feature.linkTxt` is a variable that is generated in a `ngFor` loop, that is why I don't have the `' '` around it. – don Dec 23 '16 at 06:06
  • Have you tried `feature.linkTxt` ? – ranakrunal9 Dec 23 '16 at 06:09
  • `feature.linkTxt` is a variable, so I've tried `{{ feature.linkTxt }}` and that is working. Apparently it is a bug, I'm adding a response for this. – don Dec 23 '16 at 06:16
0

It turns out that this is a known open bug.

See https://github.com/ocombe/ng2-translate/issues/355

don
  • 4,113
  • 13
  • 45
  • 70