Console application that uses the OpenRouter API to automatically translate missing English resource keys into all other language files of the shared localization packs used by both UI apps of SimpleLauncher:
- Shared packs:
SimpleLauncher.Core\Localization\strings.*.json— master filestrings.en.json - The WPF app (
SimpleLauncher) embeds these packs at build time; the Avalonia app (SimpleLauncher.Avalonia) links/copies them toResources\strings.*.json.
- Loads the English master file (
strings.en.json) as the canonical key list. - Compares every other language file against English.
- Auto-removes duplicate keys found in target language files.
- Translates missing keys in batches of 40 via the OpenRouter chat-completions API.
- Preserves empty values from English as empty entries in target languages.
- Re-sorts each resource file alphabetically by key after writing.
- Writes files as readable UTF-8 — non-ASCII characters (Arabic, CJK, etc.) are written as-is, never as
\uXXXXescape sequences.
- .NET 11 SDK
- An OpenRouter API key (the app prompts every run and does not store it)
dotnet run --project SimpleLauncher.ResourceTranslator- The app locates the shared
SimpleLauncher.Core\Localizationfolder automatically from the solution structure. - Enter your OpenRouter API key when prompted.
- Select a model (or press Enter for the default
z-ai/glm-5.3-flash). - It prints an analysis summary: how many languages need updates, how many keys are missing, and how many duplicates will be removed.
- Press any key to proceed.
- Keys are translated in batches of 40 with a 500 ms delay between requests to avoid rate limits.
- Each language file is updated and saved automatically.
Both test suites have resource tests that keep the shared packs in sync:
DetectMissingResourceStringsTests(Avalonia) scans the Avalonia source (.csGetString(...)calls and.axaml{ext:Translate Key}usages) and auto-adds any missing key tostrings.en.jsonwith a sensible fallback value.DetectMissingResourceProviderKeysTests/DetectMissingResourceStringsTests(WPF) do the same for_resourceProvider.GetString(...)andTryFindResource(...)usages in the WPF app.LocalizationTests.EveryLanguageFileSharesTheEnglishKeySet(Avalonia) fails with a per-language list of missing keys and a pointer to this tool whenever a language file falls out of sync.
If a test fails after new English keys were auto-added, run the translator to propagate them to all languages, then re-run the tests.
Default: z-ai/glm-5.3-flash (marked (default) in the prompt). Also selectable:
| Model | Notes |
|---|---|
z-ai/glm-5.3-flash |
default; cheap and fast |
deepseek/deepseek-v4-flash |
cheapest DeepSeek flash variant |
qwen/qwen3.7-flash |
cheapest Qwen flash variant |
qwen/qwen3.8-flash |
newer Qwen flash variant |
deepseek/deepseek-v4-pro-0813 |
higher quality, slower and pricier |
Notes on model behavior:
- The request sends no
reasoningparameter. Some endpoints (e.g.z-ai/glm-5.3-flash) mandate reasoning and rejectreasoning: { enabled: false }with HTTP 400; thinking output arrives in a separatemessage.reasoningfield that is ignored. HttpClienttimeout is 10 minutes per batch, so thinking models do not time out.
SimpleLauncher.ResourceTranslator/
├── SimpleLauncher.ResourceTranslator.csproj
├── Program.cs # Entry point, user prompts, orchestration
├── Models/
│ ├── OpenRouterModelInfo.cs # Model metadata (id, name, description)
│ └── MissingKeyBatch.cs # Holds missing keys & duplicates per language
└── Services/
├── JsonResourceAnalyzer.cs # Reads English JSON keys and diffs other JSON languages
├── OpenRouterTranslationService.cs # HTTP client for OpenRouter API batch translation
└── JsonResourceWriter.cs # Writes updated JSON (UTF-8 without BOM, 2-space indent, readable)
No configuration files are used. The only runtime inputs are:
- API key (typed interactively, never persisted)
- Model selection (default:
z-ai/glm-5.3-flash)
The LLM receives each batch as a flat list of Key|Value lines and must answer with one Key|Translated value line per entry. To keep the protocol unambiguous:
- Newlines inside values are escaped as literal
\n(and back-translated on parse); literal pipes in values are escaped as\|. - Non-
Key|Valuelines in the response (reasoning echoes, markdown, explanations) are ignored by the parser.
- If a translation batch fails (network error, rate limit, etc.), the app skips that batch and does not add empty strings to the resource file. Run the app again later to retry.
- The app is safe to run multiple times; it only processes keys that are actually missing.
- Empty English values are intentionally preserved as empty entries so translators can fill them in later.
- JSON files are written as UTF-8 without a BOM, with 2-space indentation and
StringComparer.OrdinalIgnoreCasekey order — matching the committed shared resource files.