in app/exec/extension/_lib/manifest.ts [106:143]
private _getLocResult(translations: any, defaults: any, locData = {}, currentPath: string[] = []) {
// deep iterate through this.data. If the value is a string that starts with
// resource:, use the key to look in translations and defaults to find the real string.
// Do the replacement
let currentData = currentPath.length > 0 ? _.get(this.data, currentPath) : this.data;
Object.keys(currentData).forEach(key => {
// Ignore localization comments
if (key.startsWith("_") && key.endsWith(".comment")) {
return;
}
const val = currentData[key];
if (
typeof val === "string" &&
val.substr(0, ManifestBuilder.resourcePrefix.length) === ManifestBuilder.resourcePrefix
) {
const locKey = val.substr(ManifestBuilder.resourcePrefix.length);
const localized = _.get(translations, locKey) || _.get(defaults, locKey);
if (localized) {
_.set(locData, currentPath.concat(key), localized);
} else {
throw new Error("Could not find translation or default value for resource " + locKey);
}
} else {
if (typeof val === "object" && val !== null) {
if (_.isArray(val)) {
_.set(locData, currentPath.concat(key), []);
} else {
_.set(locData, currentPath.concat(key), {});
}
this._getLocResult(translations, defaults, locData, currentPath.concat(key));
} else {
_.set(locData, currentPath.concat(key), val);
}
}
});
return locData;
}