Repository navigation
One JSON file per language, read by the Mac and the Windows launcher (#388, step 1) - #478
Merged
Merged
Conversation
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.
5 of 6 tasks
# 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: # AGENTS.md
# Conflicts: # frontend-qt/nspb_qt/localization.py # frontend/Sources/NXCore/Localization.swift
4 of 6 tasks
5 of 6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #476 (stack #459), retarget to main after the ones below merge.
Part of #388, step 1.
Fix or 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:
tools/l10n_from_swift.py, wrotefrontend/l10n/{en,zh,sv,de,fr}.jsonfrom the Swift tables. Each file is a flat object, keys sorted, UTF-8 text without\uescapes, and a_languageentry first with the language's own name and the locale prefixes that select it (the Windows locale names ofnspb_qtincluded). 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.LocalizationStaleFrameworks.swiftis gone.Localization.swiftkeeps theLangchoice and the lookup, and has no translated text.LocalizationFiles.swiftreads the files once, at the first lookup. The Mac app readsContents/Resources/l10n,swift runfindsfrontend/l10nby walking up from the executable andswift testtakes it from the source path.NX_L10N_DIRnames 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.deandL10n.frstay, built from the files, so the existing tests did not change.frontend-qt/nspb_qt/l10n.pyreplaceslocalization.py. It keepsTABLEandt(), finds the files in the PyInstaller bundle'sl10nfolder or in the checkout, and has the same failure behavior.gen_localization.pyandlocalization.pyare deleted. The Qt tests import the new module.build-mac-app.yml,tools/try-localandfrontend/tools/check_bundle.shput the folder intoContents/Resources/l10nand check it.build-qt.ymladds it with--add-data, likefrontend/fonts. The two checks that regenerated the Qt table (tests.yml, the pre-push hook) are gone. A change underfrontend/l10n/gets thewindowslabel too.SourceSizeTestsloses its entry forLocalization.swift.frontend/README.md(section Language),frontend/ARCHITECTURE.md,frontend-qt/README.mdandAGENTS.mdsay where the texts live. A new string is a line inen.jsonandzh.json.Proposal for the two open questions in #388:
frontend/l10n/<code>.json, next tofrontend/fonts/, not in a top-level folder.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
L10nAPI 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. ResolvedL10n.stringfor 1054 keys (the 1053 plus an unknown key) in each of the five languages: 0 differences. The Python side: the oldlocalization.pyTABLEhas 1048 keys, and for each of the five languages all 1048 match the JSON (0 differences). The newl10n.TABLEequals 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.cd frontend && swift test4 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 areLocalizationFilesTests.python3 -m unittest discover -s frontend-qt/tests: 218 tests OK (14 skipped).python3 -m unittest discover tools/tests: 148 OK.NX_LAUNCHER_CAPTURE_DIR=<dir> swift testbefore 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).Screenshots
None, no visible change. I compared the launcher views before and after by pixel in all five languages (see Checked).
Scope
dm/,scripts/,docs/,ref/) is added to the repository