attranslate
Version:
Semi-automated Text Translator for Websites and Apps
63 lines (62 loc) • 2.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FlutterArb = void 0;
const util_1 = require("../../util/util");
const format_cache_1 = require("../common/format-cache");
const managed_json_1 = require("../common/managed-json");
const attributeCache = new format_cache_1.FormatCache();
class FlutterArb {
readTFile(args) {
const json = (0, managed_json_1.readManagedJson)(args.path);
const tMap = new Map();
const globalAttributes = {};
for (const key of Object.keys(json)) {
const value = json[key];
if (key.startsWith("@@")) {
globalAttributes[key] = value;
}
else if (key.startsWith("@") && value && typeof value === "object") {
attributeCache.insert({
path: args.path,
key,
entry: value,
});
}
else if (typeof value === "string") {
tMap.set(key, value);
}
else {
console.info(`Warning: '${key}-${value}' in ${(0, util_1.getDebugPath)(args.path)} is unexpected`);
}
}
const fileCache = attributeCache.findFileCache(args.path);
if (fileCache) {
fileCache.auxData = { globalAttributes };
}
return Promise.resolve(tMap);
}
writeTFile(args) {
const json = {};
args.tSet.forEach((value, key) => {
json[key] = value;
const attributeKey = `@${key}`;
const cachedAttributes = attributeCache.lookup({
path: args.path,
key: attributeKey,
});
if (cachedAttributes) {
const mergedAttributes = {
...cachedAttributes,
};
json[attributeKey] = mergedAttributes;
}
});
const auxData = attributeCache.lookupAuxdata({ path: args.path });
const mergedJson = {
...auxData === null || auxData === void 0 ? void 0 : auxData.globalAttributes,
...json,
};
(0, managed_json_1.writeManagedJson)({ path: args.path, object: mergedJson });
}
}
exports.FlutterArb = FlutterArb;