core icon indicating copy to clipboard operation
core copied to clipboard

Refresh translation with params after param value changes

Open rmartin94 opened this issue 6 years ago • 8 comments

Hi, I'm trying to know if its possible to reload a certain translation which holds a parameter when the param value changes.

json

{
    "HELLO": "hello {{value}}"
}

html <button (click)="change()">{{ 'HELLO' | translate:param }}</button>

component

constructor(private translate: TranslateService) {
     ...
}
param = {value: 'world'};

change(){
       this.param.value = 'earth';
       //this.translate.use(this.translate.currentLang);
       //this.translate.resetLang(this.translate.currentLang);
      //this.translate.reloadLang(this.translate.currentLang);
}

I've tryed to force the translation to re-translate again when clicking the button by calling the methods from the translate service commented above but it didn't work. Is this something possible to do? Thanks in advance, the library is great!

I'm Using library version 9 since this is from an Angular 5 project

rmartin94 avatar May 19 '18 13:05 rmartin94

@rmartin94 Did you find a solution? This is driving me crazy right now and it seems nobody is posting a good workaround

Qocotzxin avatar Jul 04 '18 16:07 Qocotzxin

The only solution I can think of at this point is to split the translation strings in your view and use interpolation on your variable between the two, or -

Hide and show the containing component of your single translation string if the values change in some way :/

jarodsmk avatar Jan 30 '19 11:01 jarodsmk

Why not add two-way binding for translation params ?

monkeycatdog avatar Feb 05 '19 12:02 monkeycatdog

+1

raschle avatar Mar 15 '19 12:03 raschle

+1

VictorComeGuillon avatar Mar 18 '19 09:03 VictorComeGuillon

I could refresh the params, but I had to replace the whole object with a new object, instead of replacing each property in the old params object.

cesar2064 avatar Apr 10 '19 13:04 cesar2064

I could refresh the params, but I had to replace the whole object with a new object, instead of replacing each property in the old params object.

Thanks, @cesar2064. Refreshing the whole object did the trick.

nelson6e65 avatar Oct 21 '20 23:10 nelson6e65

I could refresh the params, but I had to replace the whole object with a new object, instead of replacing each property in the old params object.

Thanks

davidarroyo1234 avatar Feb 07 '22 08:02 davidarroyo1234