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

Function addToAllFiles

utils/lang.js:67–101  ·  view source on GitHub ↗

* Adds a key-value pair to ALL language files at once * Usage: pnpm lang add-all "key" "value"

()

Source from the content-addressed store, hash-verified

65 * Usage: pnpm lang add-all "key" "value"
66 */
67function addToAllFiles() {
68 if (!arg || !val) {
69 console.error('Usage: pnpm lang add-all "<key>" "<value>"');
70 console.error('Example: pnpm lang add-all "hello world" "Hello World"');
71 process.exit(1);
72 }
73
74 const key = arg.toLowerCase();
75 let addedCount = 0;
76 let skippedCount = 0;
77
78 for (const lang of list) {
79 const file = path.resolve(dir, lang);
80 const text = fs.readFileSync(file, "utf8");
81 const strings = JSON.parse(text);
82
83 if (key in strings) {
84 console.log(`${lang}: Skipped (already exists)`);
85 skippedCount++;
86 continue;
87 }
88
89 strings[key] = val;
90 const newText = JSON.stringify(strings, undefined, 2);
91 fs.writeFileSync(file, newText, "utf8");
92 console.log(`${lang}: Added ✓`);
93 addedCount++;
94 }
95
96 console.log(
97 `\nDone! Added to ${addedCount} files, skipped ${skippedCount} files.`,
98 );
99 createTypes();
100 process.exit(0);
101}
102
103/**
104 * Bulk add multiple strings from a JSON file to ALL language files

Callers 1

lang.jsFile · 0.85

Calls 4

createTypesFunction · 0.85
exitMethod · 0.80
logMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected