Consider the following script:
let object = {
text1: 'this is text1',
text2: 'this is text2'
}
class Translate {
constructor() {
this.localization = null;
this.lateForTheShow = [];
init();
}
async init() {
/** Perform an ajax call to fetch a localization file **/
this.localization = await ajaxCall(...);
for (let i in this.lateForTheShow) {
this.translate(this.lateForTheShow[i].originalText, this.lateForTheShow[i].referencedVariable);
}
}
translate(text, &pointer) {
if (this.localization === null) {
this.lateForTheShow.push({
referencedVariable: pointer,
originalText: text
});
} else {
text = this.localization[text];
}
pointer = text;
}
}
let TranslateObj = new Translate();
TranslateObj.translate(object.text1, object.text1);
The above code is not a valid javascript code, because you can't pass pointers to variables in javascript (at least certainly not the PHP
way I did pass them). Something like this could be done in PHP
although, and I am wondering if something simmilar could be achiavable in javascript, or not?