-
-
Notifications
You must be signed in to change notification settings - Fork 586
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
Setting another value for a translation key should be updated #216
Comments
Good point, I'll have to fix that :) |
Thank you. I have a possible implementation for the problem, but it's in my own service that is a wrapper for the TranslationService. If you want, I can put here the code that I have (is TypeScript), you can take a look and you can refine it and included in the TranslationService implementation. Let me know if you would like to see what I have. |
sure, that would help, thanks |
Ok. So here it is: private set(key: string, value: string): void {
let translations: any = (<any>this._translationService).translations[this._translationService.currentLang];
let path: string[] = key.split('.');
this.setDeepValue(translations, value, path);
this._translationService.onTranslationChange.emit(<TranslationChangeEvent>{
translations: translations,
lang: this._translationService.currentLang
});
}
private setDeepValue(obj: any, value: any, path: string[]): void {
if (path.length > 1) {
let fragment: string = path.shift();
if (obj[fragment] == null || typeof obj[fragment] !== 'object') {
obj[fragment] = {};
}
this.setDeepValue(obj[fragment], value, path);
} else {
obj[path[0]] = value;
}
} where |
@ocombe |
Yes, I would also like this fixed. |
Any update on this issue ? |
any updates. Why this is still getting issue in 2020? |
@ocombe |
2021 still no updates ? |
Well we are now in 2022 and this is still not working... |
I'm submitting a ... (check one with "x")
Current behavior
From what I could see, translations member, within TranslationService, for a specific language, is not a dictionary but an object tree. For example:
so, to use one of the keys in the pipe, you simply write
The signature for setting another value for one of the key is:
so, if one wants to change from code the value of the firstName, would inject TranslationService and do
but the current implementation is not having the desired result, because, after executing the previous set, the translations object inside TranslatonService will look like this:
So, either I do not use correctly the set method, in which case the documentation should be updated, or it's internal implementation should be updated
Reproduction of the problem
If the current behavior is a bug or you can illustrate your feature request better with an example, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:btpW3l0jr5beJVjohy1Q).
Please tell us about your environment:
The text was updated successfully, but these errors were encountered: