MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / askTranslation

Function askTranslation

utils/lang.js:287–378  ·  view source on GitHub ↗
(i = 0)

Source from the content-addressed store, hash-verified

285 }
286
287 function askTranslation(i = 0) {
288 const lang = list[i];
289 const langName = lang.split(".")[0];
290 if (command === "add") {
291 if (!args.a) {
292 getStr(`${langName}: `).then(addString);
293 return;
294 }
295
296 addString();
297 } else if (command === "remove") {
298 update((strings) => {
299 if (key in strings) {
300 delete strings[key];
301 console.log(`Removed: ${key}`);
302 return strings;
303 } else {
304 console.error("String not exists");
305 }
306 });
307 } else if (command === "update-key") {
308 update((strings) => {
309 const val = strings[key];
310 delete strings[key];
311 strings[newKey] = val;
312 return strings;
313 });
314 } else if (command === "update") {
315 if (val) {
316 update((strings) => {
317 strings[key] = val;
318 return strings;
319 });
320 } else {
321 getStr(`${langName}: `).then((res) => {
322 res = res || arg;
323 update((strings) => {
324 strings[key] = res;
325 return strings;
326 });
327 });
328 }
329 } else if (command === "search") {
330 update((string) => {
331 if (key in string) console.log(`${key}(${langName}): ${string[key]}`);
332 else {
333 console.log(`${key} not exists`);
334 process.exit();
335 }
336 });
337 }
338
339 function update(modify) {
340 const file = path.resolve(dir, lang);
341 const text = fs.readFileSync(file, "utf8");
342 const strings = modify(JSON.parse(text));
343 if (strings) {
344 const newText = JSON.stringify(strings, undefined, 2);

Callers 2

updateFunction · 0.85
nextFunction · 0.85

Calls 6

getStrFunction · 0.85
addStringFunction · 0.85
logMethod · 0.80
exitMethod · 0.80
updateFunction · 0.70
errorMethod · 0.45

Tested by

no test coverage detected