Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A function returned if translations loaded by .get() method. #52

Open
rasulovdev opened this issue Nov 26, 2019 · 6 comments
Open

A function returned if translations loaded by .get() method. #52

rasulovdev opened this issue Nov 26, 2019 · 6 comments

Comments

@rasulovdev
Copy link

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?

@lephyrus
Copy link
Owner

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.

@rasulovdev
Copy link
Author

rasulovdev commented Nov 28, 2019

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.

@lephyrus
Copy link
Owner

@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 messageformat to 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.

@rasulovdev
Copy link
Author

@lephyrus, ok, I'll try to discuss this in @ngx-translate/core repo. Thanks.

@Saucistophe
Copy link

@AzamatRasulov By chance, did you have any luck with this?
I'm having the same problem and have no idea what went wrong...

@Saucistophe
Copy link

Also found a reference here. https://forum.primefaces.org/viewtopic.php?t=64937

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants