so I'm translating JSON object. so data can be placed anywhere in the object currently, I've written this below code which is only translating nestedTitle. I've to make it that there is n number of nested data it can access and translate all the data. for ref. https://stackblitz.com/edit/translate-json-data?file=src%2Fapp%2Fapp.component.ts
public dataoflang:any =
{
"title": "Hello",
"greeting": "how are you",
"nestedTitle": {
"title": "Hello",
"greeting": "how are you",
"innerNested": {
"title": "Hello",
"greeting": "how are you"
}
}
}
onTranslate() {
for (let item in this.dataoflang) {
for (let p in this.dataoflang[item]) {
this.appService
.getTranslation(this.dataoflang[item][p], this.selectedLang)
.subscribe((response) => {
let prod = response[0][0][0];
this.dataoflang[item][p] = prod;
});
}
}
}
Via Active questions tagged javascript - Stack Overflow https://ift.tt/cJpSbIP
Comments
Post a Comment