import ts from 'typescript'; import {readdir,readFile,writeFile} from 'node:fs/promises'; import {join} from 'node:path'; // One-time migration: stable IDs must never be regenerated after translations exist. if(await readFile('src/locales/en.json','utf8').catch(()=>''))throw new Error('The catalog is established. Use node scripts/append-localization.mjs to preserve translation IDs.'); const keys=new Set(); function add(value){value=value.replace(/\s+/g,' ').trim();if(value.length>1&&/[A-Za-z]{2}/.test(value)&&!/^([.#/]|https?:|data:|[\w.-]+\.(json|mjs|tsx?|py|html|svg|png|gguf)\b|\(max-width|\(prefers-)/.test(value)&&!/[{}<>;=]/.test(value)&&!/^var\(/.test(value)&&!/(?:\bst-|\bnative-|\bonboard-|\bmonitor-|\brun-|\bsettings-|\bts-|__)/.test(value))keys.add(value);} function clean(text){const lines=text.replace(/\r/g,'').split('\n');let result='';for(let i=0;i{if(ts.isTemplateExpression(node)){let key=node.head.text;node.templateSpans.forEach((span,i)=>key+=`{${i}}${span.literal.text}`);const plain=key.replace(/\{\d+\}/g,'');if(/[A-Za-z]{2} /.test(plain)&&!/[<>\n\t]/.test(plain)&&!/^https?:|^[.#/]|^var\(/.test(plain))keys.add(key.trim());}ts.forEachChild(node,walk);};walk(sf);}}} // Remove the temporary placeholders used by the broad literal pass. for(const key of keys)if(key.includes('PLACEHOLDER'))keys.delete(key); await templates('src'); const result=Object.fromEntries([...keys].sort().map((key,index)=>[`s${String(index+1).padStart(4,'0')}`,key])); await writeFile('src/locales/en.json',JSON.stringify(result,null,2)+'\n'); console.log(`${keys.size} interface strings`);