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

Function update

utils/lang.js:181–379  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

179}
180
181async function update() {
182 let key;
183
184 if (command === "check") {
185 let error = false;
186 const fix = arg === "fix";
187 const enLangData = JSON.parse(fs.readFileSync(enLang, "utf8"));
188 const enKeys = Object.keys(enLangData);
189
190 for (const file of list) {
191 if (file === "en-us.json") continue;
192
193 let flagError = false;
194 const langFile = path.join(dir, file);
195 const langData = JSON.parse(fs.readFileSync(langFile, "utf8"));
196
197 const langError = () => {
198 if (!flagError) {
199 error = true;
200 flagError = true;
201 console.log(`-------------- ${file}`);
202 }
203 };
204
205 for (const enKey of enKeys) {
206 const key = Object.keys(langData).find((k) => {
207 try {
208 return new RegExp(`^${escapeRegExp(k)}$`, "i").test(enKey);
209 } catch (e) {
210 console.log({ e, k });
211 return false;
212 }
213 });
214
215 if (!key) {
216 langError();
217 if (fix) {
218 langData[enKey] = enLangData[enKey];
219 }
220
221 console.log(`Missing: ${enKey} ${fix ? "✔" : ""}`);
222 } else if (key !== enKey) {
223 langError();
224 console.log(`Fix: "${key} --> ${enKey}" ${fix ? "✔" : ""}`);
225
226 if (fix) {
227 const val = langData[key];
228 delete langData[key];
229 langData[enKey] = val;
230 }
231 }
232 }
233
234 for (const key in langData) {
235 const enKey = enKeys.find((k) => {
236 try {
237 return new RegExp(`^${escapeRegExp(k)}$`, "i").test(key);
238 } catch (e) {

Callers 3

lang.jsFile · 0.70
askTranslationFunction · 0.70
addStringFunction · 0.70

Calls 9

langErrorFunction · 0.85
getStrFunction · 0.85
askTranslationFunction · 0.85
logMethod · 0.80
exitMethod · 0.80
escapeRegExpFunction · 0.70
nextFunction · 0.70
writeFileMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected