Ver Fonte

fix: respect tr-prep -k option when some keys are undefined

Sv443 há 5 dias atrás
pai
commit
4d76ce6f1a
1 ficheiros alterados com 11 adições e 0 exclusões
  1. 11 0
      src/tools/tr-format.ts

+ 11 - 0
src/tools/tr-format.ts

@@ -37,7 +37,12 @@ async function run() {
     if(!includeBased && localeObj.meta.base)
       continue;
 
+    const undefKeys: string[] = [];
+
     for(const k of Object.keys(enUS_obj)) {
+      if(localeObj[k] === undefined)
+        undefKeys.push(k);
+
       // special treatment for the meta block
       if(k === "meta") {
         localeFile = localeFile.replace(/"meta":\s+{[^}]+\s{2}},?/m, `"meta": ${JSON.stringify(localeObj.meta, null, 2).replace(/\n/gm, "\n  ")},`);
@@ -64,6 +69,12 @@ async function run() {
       }
     }
 
+    // if onlyKeys is set, remove all lines with keys that are in undefKeys, *excluding* the ones in onlyKeys
+    if(onlyKeys)
+      for(const k of undefKeys)
+        if(!onlyKeys.includes(k))
+          localeFile = localeFile.replace(new RegExp(`\\n\\s+"${k}":\\s+".*",?`, "m"), "");
+
     // remove last trailing comma if present
 
     const pattern = /^\s*".*":\s+".*",?$/gm;