Skip to content

One JSON file per language, read by the Mac and the Windows launcher (#388, step 1) - #478

Merged
v0lumehi merged 10 commits into
v0lumehi/launcher-cardsfrom
v0lumehi/l10n-json
Nov 2, 2026
Merged

v0lumehi merged 10 commits into
v0lumehi/launcher-cardsfrom
v0lumehi/l10n-json

Conversation

@v0lumehi

@v0lumehi v0lumehi commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #476 (stack #459), retarget to main after the ones below merge.

Part of #388, step 1.

Fix or feature

  • Fix
  • Feature

What and why

The launcher's texts were Swift source: 4237 lines in Localization.swift, 283 Chinese rows as \u{...} escapes, and a generator that read the Swift file with regular expressions to write the Qt table. This is step 1 of #388. The texts move into one JSON file per language and both launchers read the same files.

What changes:

  • A one-time script, tools/l10n_from_swift.py, wrote frontend/l10n/{en,zh,sv,de,fr}.json from the Swift tables. Each file is a flat object, keys sorted, UTF-8 text without \u escapes, and a _language entry first with the language's own name and the locale prefixes that select it (the Windows locale names of nspb_qt included). The script says in its docstring that a later step of One JSON file per language, read by the Mac launcher, the Windows launcher and the iOS shell #388 deletes it.
  • The five strings of the stale-frameworks prompt (Ask before the build when the shared app holds frameworks of an old shader chain #450) are in the files too, LocalizationStaleFrameworks.swift is gone.
  • Localization.swift keeps the Lang choice and the lookup, and has no translated text. LocalizationFiles.swift reads the files once, at the first lookup. The Mac app reads Contents/Resources/l10n, swift run finds frontend/l10n by walking up from the executable and swift test takes it from the source path. NX_L10N_DIR names another folder. A missing or broken file does not stop the app: the lookup shows English, then the key (as today for a missing key), and one line goes to standard error. L10n.table, L10n.sv, L10n.de and L10n.fr stay, built from the files, so the existing tests did not change.
  • frontend-qt/nspb_qt/l10n.py replaces localization.py. It keeps TABLE and t(), finds the files in the PyInstaller bundle's l10n folder or in the checkout, and has the same failure behavior. gen_localization.py and localization.py are deleted. The Qt tests import the new module.
  • build-mac-app.yml, tools/try-local and frontend/tools/check_bundle.sh put the folder into Contents/Resources/l10n and check it. build-qt.yml adds it with --add-data, like frontend/fonts. The two checks that regenerated the Qt table (tests.yml, the pre-push hook) are gone. A change under frontend/l10n/ gets the windows label too.
  • SourceSizeTests loses its entry for Localization.swift.
  • Docs: frontend/README.md (section Language), frontend/ARCHITECTURE.md, frontend-qt/README.md and AGENTS.md say where the texts live. A new string is a line in en.json and zh.json.

Proposal for the two open questions in #388:

  1. The files live in frontend/l10n/<code>.json, next to frontend/fonts/, not in a top-level folder.
  2. The shell's keys become dotted keys like the launcher's (for example shell.settings.back). That is step 5 and this PR does not touch the shell.

Open translation PRs conflict with this. #352 (Italian, from a fork) has to be redone in the new files after this lands. I did not touch it.

No text was changed. The Swedish file has 877 keys because that overlay never had the others, so they show English as before.

Checked

  • Conversion proof. I loaded the old Swift tables through the L10n API in a throwaway test (not committed) and compared every (language, key) value with the JSON, with the English fallback applied. Raw tables: zh 1053, en 1053, sv 877, de 1053, fr 1053 keys, 0 differences, no key on one side only. Resolved L10n.string for 1054 keys (the 1053 plus an unknown key) in each of the five languages: 0 differences. The Python side: the old localization.py TABLE has 1048 keys, and for each of the five languages all 1048 match the JSON (0 differences). The new l10n.TABLE equals the old one for those 1048 keys in every column, and has the 5 stale-frameworks keys more. Nothing in the Swift file was computed: no interpolation, no +, no multi-line literals.
  • Tests: cd frontend && swift test 4 times (three full runs and the pre-push hook), all green, 873 tests over the three bundles (NXModelTests 118, NXCoreTests 118, NX2AppleTests 637 with 17 skipped captures), the previous step had 868. The 5 new ones are LocalizationFilesTests. python3 -m unittest discover -s frontend-qt/tests: 218 tests OK (14 skipped). python3 -m unittest discover tools/tests: 148 OK.
  • Visual QA: NX_LAUNCHER_CAPTURE_DIR=<dir> swift test before and after, in en, zh, de, sv and fr, 42 views per language compared by pixel. 28 per language are identical, including library, library-search, settings, settings-update-* and controls. The 14 that differ are the same in each language (the build pages, progress-bars, saves, saves-confirm and two settings-zip views). Their differences are small boxes of single text lines where a random temp path or a time of day is drawn, which changes by itself on every run (in saves-confirm the longer path also wraps differently, the words are the same).
  • Run on a Mac or Windows: not run. The release app and the Windows build are not built here, so "all five languages in a build from the workflow" in One JSON file per language, read by the Mac launcher, the Windows launcher and the iOS shell #388's "Done when" is still to be checked by hand on the workflow's artifacts.

Screenshots

None, no visible change. I compared the launcher views before and after by pixel in all five languages (see Checked).

Scope

  • No engine file (dm/, scripts/, docs/, ref/) is added to the repository
  • No engine change, no patch
  • No launcher view changes, so no screenshots are needed
  • No keys, game files or data extracted from a game in the change

A one-time converter reads the Swift tables and writes en, zh, sv, de and fr as one flat JSON object per language: keys sorted, UTF-8 without escapes, a _language entry with the language's own name and the locale prefixes that select it. The strings of the stale-frameworks prompt are in the files too. Nothing reads them yet.
Localization.swift keeps the language choice and the lookup. LocalizationFiles reads frontend/l10n once, from Contents/Resources/l10n in the app, by walking up from the executable under swift run and from the source path under swift test. A missing or broken file is reported once on standard error and the lookup shows English, then the key. The stale-frameworks table is gone: its texts are in the files.
nspb_qt/l10n.py reads frontend/l10n, from the PyInstaller bundle's l10n folder or from the checkout, and keeps the same TABLE and t() that localization.py had. gen_localization.py and localization.py are deleted. The Qt tests import the new module.
…texts live (#388)

build-mac-app.yml, tools/try-local and check_bundle.sh put frontend/l10n into Contents/Resources/l10n and check it. build-qt.yml adds the folder with --add-data. The generated-table checks in tests.yml, the pre-push hook and build-qt.yml are gone. A change under frontend/l10n gets the windows label too.
@v0lumehi v0lumehi added this to the v1.0.2 milestone Nov 2, 2026
@v0lumehi v0lumehi added enhancement New feature or request launcher The NX2Apple launcher app mac Mac windows Windows (the Qt front end) labels Nov 2, 2026
@github-actions github-actions Bot added documentation Improvements or additions to documentation ci Workflows and repository tooling labels Nov 2, 2026
@v0lumehi
v0lumehi added this pull request to stack #459 November 2, 2026 03:53
# Conflicts:
#	frontend-qt/nspb_qt/localization.py
#	frontend/Sources/NX2Apple/ContentView.swift
#	frontend/Sources/NXCore/Localization.swift
#	frontend/Sources/NXCore/ShellInstall.swift
#	frontend/Tests/NX2AppleTests/ShellInstallTests.swift
# Conflicts:
#	frontend/Sources/NXModel/BuildStore+ShellRoot.swift
# Conflicts:
#	frontend-qt/nspb_qt/localization.py
#	frontend/Sources/NXCore/Localization.swift
@v0lumehi v0lumehi mentioned this pull request Nov 2, 2026
4 of 6 tasks
@v0lumehi
v0lumehi merged commit d9ae970 into main Nov 2, 2026
18 of 21 checks passed
@v0lumehi
v0lumehi deleted the v0lumehi/l10n-json branch November 2, 2026 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Workflows and repository tooling documentation Improvements or additions to documentation enhancement New feature or request launcher The NX2Apple launcher app mac Mac windows Windows (the Qt front end)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant