ngx-translate-messageformat-compiler
ngx-translate-messageformat-compiler copied to clipboard
A function returned if translations loaded by .get() method.
Translations returned as functions when I try to load them async. So I need to execute the key to access the value.
this.translate.get('shared').subscribe(translations => {
console.log(translations.key) // Function { return 'Value' }
console.log(translations.key()) // Value
});
Is it intended to work like this?
From the ngx-translate README:
get(key: string|Array<string>, interpolateParams?: Object): Observable<string|Object>: Gets the translated value of a key (or an array of keys) or the key if the value was not found
So no, I don't think that's expected. This most probably needs to be investigated and fixed in @ngx-translate/core. I don't have time to look into that at the moment, unfortunately. If you decide to tackle this yourself, @AzamatRasulov, feel free to let me know your findings and I can try to support the effort.
This most probably needs to be investigated and fixed in
@ngx-translate/core.
This behaviour occur only if I use TranslateMessageFormatCompiler. The default ngx-translate TranslateCompiler doesn't produce this issue. I should've mentioned it initially, sorry.
@AzamatRasulov Oh, absolutely - it wouldn't affect the default compiler. In order to do be able to write this plugin (which does very little - look at the code), I've submitted a PR to get two things into @ngx-translate/core:
- a plugable compile step (which does nothing by default, but with this plugin uses
messageformatto compile the ICU syntax to a function) - support for "function interpolation" (
(expr: string, params: any) => string) in addition to "string interpolation" ((expr: Function, params: any) => string)
From what you're saying, get doesn't seem to work correctly with function interpolation.
@lephyrus, ok, I'll try to discuss this in @ngx-translate/core repo. Thanks.
@AzamatRasulov By chance, did you have any luck with this? I'm having the same problem and have no idea what went wrong...
Also found a reference here. https://forum.primefaces.org/viewtopic.php?t=64937