core
core copied to clipboard
Refresh translation with params after param value changes
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 Did you find a solution? This is driving me crazy right now and it seems nobody is posting a good workaround
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 :/
Why not add two-way binding for translation params ?
+1
+1
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.
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.
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