Files
Strata/app/host/scripts/localization-catalog.mjs
T
Niko1221 4058aa782b Layout move for 0.2.16: the top level becomes app/, engine/, terminal/, docs/, tools/ and .github/
Made by tools/layout/move_0216.py (the commit before this one) on db8e0be9c, the final code head of 0.2.16:
- 75 git mv (renames, so `git log --follow` and blame keep working; packaging/acceptance_matrix.md shows as delete + add because its links
  changed too) and 3 removals: SETUP.bat, UPDATE.bat and update.sh (setup.py --update pulls the code now);
- 1,425 path edits in 307 files: root-relative paths in CI, Docker, .gitignore and the release scripts; Markdown links; Python and
  Node joins from a root that moved with its folder; explicit edits for code that computes a root or names a moved path; tables of
  repository paths inside tests.

engine/ holds what CMake builds (src, include, cmake, metal, sycl, spark, third_party, the C++ tests and benches). app/ is the desktop
app and its host (was apps/). terminal/ is the Terminal in the layout of the installed one (strata.py, setup.py, strata_cli,
strata_control, serve, bin, data, ref, crates, the Python tools and tests). docs/ has the documentation, docs/lang/ the translated
READMEs, docs/history and docs/bench-results. tools/ has the repository's own checks, packaging, docker, research and nix.
tests/core/test_tqp_ref.py is a pytest file and stays with the Python tests (terminal/tests/core/).
AGENTS.md, README.md, LICENSE, setup.sh and START-HERE.bat stay at the root.

No behaviour change: the same command lines, the same sources. For this head a replay of the script gave the same numbers and the path
scan (tools/layout/checks/path_scan.py) reports no hit; the suites and the builds run on this commit next.
2026-11-17 13:19:21 +01:00

35 lines
5.1 KiB
JavaScript

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<lines.length;i++){let line=lines[i].replace(/\t/g,' ');if(i)line=line.replace(/^ +/,'');if(i<lines.length-1)line=line.replace(/ +$/,'');if(line){result+=line;if(i<lines.length-1)result+=' ';}}return result;}
function visit(node){
if(ts.isJsxText(node))add(clean(node.text));
if(ts.isStringLiteral(node)||ts.isNoSubstitutionTemplateLiteral(node)){
const p=node.parent;
if(ts.isJsxAttribute(p)&&! /^(title|label|hint|description|placeholder|alt|ariaLabel|aria-label|aria-description)$/.test(p.name.getText()))return;
if(ts.isPropertyAssignment(p)&&/^(className|id|key|aliases|path|url|href|args|command|value|type|style)$/.test(p.name.getText().replace(/['"]/g,'')))return;
if(node.getSourceFile().fileName.startsWith('server/')&&! (ts.isPropertyAssignment(p)&&/^(label|hint|title|detail|description|about|message|phaseLabel)$/.test(p.name.getText().replace(/['"]/g,''))||ts.isNewExpression(p)&&/Error$/.test(p.expression.getText())||ts.isCallExpression(p)&&p.expression.getText()==='error'))return;
if(ts.isJsxAttribute(p)&&/^(title|label|hint|description|placeholder|alt|ariaLabel|aria-label|aria-description)$/.test(p.name.getText()))add(node.text);
else if(ts.isPropertyAssignment(p)&&/^(label|hint|title|detail|description|about|name|section|heading|action|emptyLabel|phaseLabel)$/.test(p.name.getText().replace(/['"]/g,'')))add(node.text);
else if(/[A-Za-z][ ,!?…:–—][A-Za-z ]/.test(node.text)&&!/[\n\t]/.test(node.text))add(node.text);
else if(ts.isReturnStatement(p)||ts.isConditionalExpression(p)||ts.isJsxExpression(p))add(node.text);
}
ts.forEachChild(node,visit);
}
async function scan(dir){for(const entry of await readdir(dir,{withFileTypes:true})){const path=join(dir,entry.name);if(entry.isDirectory())await scan(path);else if(/\.(tsx?|mjs)$/.test(path)&&!path.includes('/locales/')&&!path.includes('chat-showcase')&&!path.includes('localization-catalog')){const source=await readFile(path,'utf8');const sf=ts.createSourceFile(path,source,ts.ScriptTarget.Latest,true,path.endsWith('.tsx')?ts.ScriptKind.TSX:ts.ScriptKind.TS);visit(sf);}}}
await scan('src');
await scan('server');
const extra=['Strata font','Font','Choose an installed font for the interface and conversations.','Use a font from your computer','Choose a system font','Font family','Installed fonts','Enter a font family name','Apply font','Language','Choose the language used throughout Strata.','English','Chinese','Japanese','Deutsch','Spanish','Russian','Portuguese','Korean','Loading installed fonts…','Your browser cannot list installed fonts. Enter the name of a font installed on your computer.','This model needs a newer engine.','Update your engine or import a local GGUF for this model.','Update engine','Swift 1.5','Coder','Unsloth','No GPU readings yet','No recorded speed samples yet','Expert settings','Ready','Available','Downloaded','Fastest','Compact','Balanced','High quality','Coding','Automatic','System','Appearance','Models','Storage','Engine','About','General','Reading & focus','Update','Privacy','Time-skip','Goal','Loop','Subagents','Welcome','Your model','Prepare','Make it yours'];extra.forEach(add);
// Template keys retain numbered interpolation slots for grammar and word order.
async function templates(dir){for(const entry of await readdir(dir,{withFileTypes:true})){const path=join(dir,entry.name);if(entry.isDirectory()){if(entry.name!=='locales')await templates(path);}else if(/\.(tsx?|mjs)$/.test(path)){const source=await readFile(path,'utf8'),sf=ts.createSourceFile(path,source,ts.ScriptTarget.Latest,true,path.endsWith('.tsx')?ts.ScriptKind.TSX:ts.ScriptKind.TS);const walk=node=>{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`);