-
-
Notifications
You must be signed in to change notification settings - Fork 588
Allow to override getValue method #1510
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
Comments
Currently there's no way to override it. I've removed it from the parser because the idea of the parser is about parsing/interpolating the translation message. The getValue() method was misplaced in this class - and even worse was used for 2 purposes:
Which of the functionality do you want to override? |
The goal is to be able to override a key. |
That is indeed not accessible at the moment. The probably best way to do that currently would be in the loader by merging both objects into a single one, where the overrides "win". I might also come up with a new class that will be responsible for storing and accessing the translations instead of keeping that code spread in the service itself. |
The problem is that we want to have the overrides or not, without having to reload the locales.
Having a service for this would be amazing. In the meantime, I will stay with the previous version and continue to think about an alternative. |
We are faced with the same problem. To solve it, I had to copy the TranslateDefaultParser and in a copied option to add the logic around getValue. |
We face also this issue. Custom extended version of TranslateDefaultParser with specific handling on keys (override getValue). |
We also face this issue. We use the |
@JulienBier I understand your motivation for this change. Though I also think it severly limits the use of providing custom behavior to the library (in this case a custom TranslateParser). A simple solution might be to isolate |
Yes, as long as there is a way to override it. |
protected getInterpolationReplacement(params: InterpolationParameters, key: string): string
{
return this.formatValue(getValue(params, key), key);
} So - this changes the "getValue()" which is part of the parser to implement the interpolation. It should help those cloning the TranslateParser to modify how a key is replaced / formatted. I'm now also using a separate formatValue() function that renders objects that don't provide in toString() function into JSON instead of But this is not yet the change @JulienBier wanted as I understand it - that would be the selection of a key - but that is not part of the parser anymore. |
…nslateDefaultParser - All methods in the default parser are now protected to allow overriding - added getInterpolationReplacement() to allow customization of the replacements (getting values from the parameter object and formatting) - Improved formatter now renders Objects as JSON instead of [object Object] - Arrays are rendered with ", " instead of just ","
This is still a work in progress.
This should allow the customizations @JulienBier wanted. |
This sounds like it might work; is there some way to obtain (release candidate) packages with the suggested addition (or should I say: revert)? |
Amazing. I am looking at the changes and I try to figure how I could override the getValue in the store service? |
Just derive from the store... |
By now, I tested this, and concluded that it works just as well. Right now, I juggled a local build, but would like to see this in a released package. I already forked this, and am contemplating publishing this version via npm on my own. We need this to go forward with upgrades of several packages and apps, for this we can't wait much longer! So... @CodeAndWeb , publish this as a new version ASAP, please! |
@CodeAndWeb we are also eagerly waiting for a package release of this change! @wamasimba let me know if you deployed it, such that we have an alternative to use |
@CodeAndWeb anything we can help you out with wrt the merged changes? E.g. tests, docs, examples... |
As the next release is taking waaaay too long, I released the current state of this repo as |
Current behavior
Cannot override
getValue()
methodExpected behavior
Define my own
getValue()
methodWhat is the motivation / use case for changing the behavior?
In the previous version 15.0.0, I could override the getValue method in TranslateDefaultParser, to have my own local override implementation. But in the version 16.0.0, the
getValue()
cannot be overriden anymorehttps://ngx-translate.org/getting-started/migration-guide/#24-translateparser-getvalue
How do you think that we should implement this?
Is there a way to inject my own
getValue
method in the app ?Thank you for that nice library.
The text was updated successfully, but these errors were encountered: