ng2-translate directive not working while pipe is

1k views Asked by At

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"> ...
2

There are 2 answers

0
don On BEST ANSWER

It turns out that this is a known open bug.

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

3
ranakrunal9 On

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>