Add native interface localization with external TOML locales #4914

Closed
github-bot wants to merge 1 commit from github-bot/gh-4913 into main AGit
Owner

@⁠WanderLinks on GitHub · 2026-12-01 13:39 UTC · original
WanderLinks:feature/native-i18n → main · +3359 −170 · 16 files · 1 commits · closed without merging

What it changes

Adds a native, data-driven interface localization layer so the launcher's
own menus can run in languages other than English.

  • New victory-i18n crate: a Localizer with key-based lookup, a TOML
    catalog with {placeholder} rendering, locale discovery across search
    roots, a fallback chain (locale -> bare language -> English), and runtime
    switching behind a process-wide lock.
  • Every user-facing string in the F1 menu and the F3 stats panel resolves
    through it. English is kept as an in-code fallback, so a missing key or
    locale file is never fatal.
  • The first F1 row is now an interface-language selector. Switching applies
    immediately and the choice is persisted for the next launch.
  • Locales are plain external TOML (locales/en.toml, locales/zh-CN.toml,
    494 keys each). Dropping a new .toml into a locale directory makes it
    appear in the selector without code changes or rebuilding. The build
    script copies the repository locales next to the executable.
  • No new font rasterizer and no translation engine: the existing GDI Unicode
    canvas (host/font.rs) already renders non-Latin scripts through system
    font fallback. This change is language data plus lookup only.

Pre-existing Clippy failure on main (not introduced here)

main itself does not pass the Clippy gate under the pinned toolchain. The
five findings in font.rs (two too_many_arguments), menu.rs
(manual_is_multiple_of) and panel.rs (two collapsible_if) reproduce on
a clean checkout of 5fabb46, and the 5fabb46 push run fails at the
Clippy step. They are unrelated to this change and are fixed separately in
#4708 (also #4680). This branch therefore shows the same Clippy red until
that lands; none of the new victory-i18n code produces a Clippy warning.

How it was tested

  • GPU and profile: no GPU/rendering path changes. Built and checked on
    Windows with the pinned 1.98.1 toolchain.
  • Before / After: not a performance change; no frame-rate or shader
    behaviour changes.
  • For shader changes, the wave sizes tested: not applicable (no shader
    changes).
  • cargo test passed for the crates it touches: yes. cargo test -p victory-i18n (21 passed) and the whole workspace builds with --locked.
    The full cargo test --workspace is gated only by the pre-existing
    Clippy failure described above; the heavy GPU end-to-end tests are memory
    sensitive on this 16 GB host and pass when run individually, unrelated to
    this change.
  • Also confirmed cargo xtask policy passes (472 files), and the build
    script copies both locales next to the debug and release executables.
    Commit tested: see the branch head.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files
    this touches. No open PR adds interface localization. The separate Clippy
    fix #4708 / #4680 is what this needs for a green check. The UI rework #4712
    has a different goal (categorized F1 menu, live scale, compact F3) but also
    edits menu.rs / panel.rs, so it may need a rebase if it lands first; the
    changes are otherwise independent.
**@⁠WanderLinks** on GitHub · 2026-12-01 13:39 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4913) `WanderLinks:feature/native-i18n` → `main` · +3359 −170 · 16 files · 1 commits · closed without merging ## What it changes Adds a native, data-driven interface localization layer so the launcher's own menus can run in languages other than English. - New `victory-i18n` crate: a `Localizer` with key-based lookup, a TOML catalog with `{placeholder}` rendering, locale discovery across search roots, a fallback chain (locale -> bare language -> English), and runtime switching behind a process-wide lock. - Every user-facing string in the F1 menu and the F3 stats panel resolves through it. English is kept as an in-code fallback, so a missing key or locale file is never fatal. - The first F1 row is now an interface-language selector. Switching applies immediately and the choice is persisted for the next launch. - Locales are plain external TOML (`locales/en.toml`, `locales/zh-CN.toml`, 494 keys each). Dropping a new `.toml` into a locale directory makes it appear in the selector without code changes or rebuilding. The build script copies the repository locales next to the executable. - No new font rasterizer and no translation engine: the existing GDI Unicode canvas (`host/font.rs`) already renders non-Latin scripts through system font fallback. This change is language data plus lookup only. ### Pre-existing Clippy failure on main (not introduced here) `main` itself does not pass the Clippy gate under the pinned toolchain. The five findings in `font.rs` (two `too_many_arguments`), `menu.rs` (`manual_is_multiple_of`) and `panel.rs` (two `collapsible_if`) reproduce on a clean checkout of `5fabb46`, and the `5fabb46` push run fails at the Clippy step. They are unrelated to this change and are fixed separately in #4708 (also #4680). This branch therefore shows the same Clippy red until that lands; none of the new `victory-i18n` code produces a Clippy warning. ## How it was tested - GPU and profile: no GPU/rendering path changes. Built and checked on Windows with the pinned 1.98.1 toolchain. - Before / After: not a performance change; no frame-rate or shader behaviour changes. - For shader changes, the wave sizes tested: not applicable (no shader changes). - `cargo test` passed for the crates it touches: yes. `cargo test -p victory-i18n` (21 passed) and the whole workspace builds with `--locked`. The full `cargo test --workspace` is gated only by the pre-existing Clippy failure described above; the heavy GPU end-to-end tests are memory sensitive on this 16 GB host and pass when run individually, unrelated to this change. - Also confirmed `cargo xtask policy` passes (472 files), and the build script copies both locales next to the debug and release executables. Commit tested: see the branch head. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. No open PR adds interface localization. The separate Clippy fix #4708 / #4680 is what this needs for a green check. The UI rework #4712 has a different goal (categorized F1 menu, live scale, compact F3) but also edits `menu.rs` / `panel.rs`, so it may need a rebase if it lands first; the changes are otherwise independent.
Introduces a new victory-i18n crate that owns the language layer only:
a Localizer trait with a key-based lookup, a TOML message catalog with
{placeholder} rendering, locale discovery across search roots, a fallback
chain (locale -> bare language -> English), and runtime switching behind
a process-wide lock. Every user-facing string in the F1 menu and the F3
stats panel now resolves through it, with English kept as an in-code
fallback so a missing locale file is never fatal.

Text rendering is unchanged: the existing GDI Unicode canvas already
covers non-Latin scripts through system font fallback, so this adds no
font rasterizer and no translation engine. The locales shipped in the
repository (en, zh-CN) are plain TOML; dropping a new .toml into a locale
directory makes it selectable from the interface-language row without
touching code or rebuilding. The build script copies the repository
locales next to the executable.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 13:43:53 +00:00
@ -36,0 +60,4 @@
let target = out_dir.join("..").join("..").join("..").join("locales");
// Start from a clean destination so a deleted source file does not linger.
let _ = std::fs::remove_dir_all(&target);
Author
Owner

@⁠gut0to on GitHub · 2026-12-01 13:54 UTC · original · edited 2026-12-01 14:14 UTC

Could this avoid deleting the entire locale directory beside the executable? I18n::locale_roots() searches there, and the PR describes external .toml catalogs as user-provided files; remove_dir_all therefore erases those catalogs on every rebuild. Cleaning only filenames shipped by this build, or copying without removing unrelated files, would remove stale bundled catalogs without deleting user additions. AI-assisted review: I used an AI assistant to inspect this diff.

**@⁠gut0to** on GitHub · 2026-12-01 13:54 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4913#discussion_r4755193939) · edited 2026-12-01 14:14 UTC Could this avoid deleting the entire locale directory beside the executable? `I18n::locale_roots()` searches there, and the PR describes external `.toml` catalogs as user-provided files; `remove_dir_all` therefore erases those catalogs on every rebuild. Cleaning only filenames shipped by this build, or copying without removing unrelated files, would remove stale bundled catalogs without deleting user additions. AI-assisted review: I used an AI assistant to inspect this diff.
@ -0,0 +144,4 @@
if let Some(builtin) = Builtin::ALL.iter().find(|b| b.code() == normalized) {
return Ok(Locale::Builtin(*builtin));
}
Ok(Locale::Custom(normalized))
Author
Owner

@⁠gut0to on GitHub · 2026-12-01 13:54 UTC · original · edited 2026-12-01 14:14 UTC

Could Locale::from_str reject path separators and invalid subtags before constructing Locale::Custom? ../outside currently survives normalize, file_name() becomes ../outside.toml, and load_from_roots joins it to each configured root before reading, so that lookup can escape the locale directory. A validation test for /, \, and .. would protect the root boundary. AI-assisted review: I used an AI assistant to inspect this diff.

**@⁠gut0to** on GitHub · 2026-12-01 13:54 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4913#discussion_r4755193950) · edited 2026-12-01 14:14 UTC Could `Locale::from_str` reject path separators and invalid subtags before constructing `Locale::Custom`? `../outside` currently survives `normalize`, `file_name()` becomes `../outside.toml`, and `load_from_roots` joins it to each configured root before reading, so that lookup can escape the locale directory. A validation test for `/`, `\`, and `..` would protect the root boundary. AI-assisted review: I used an AI assistant to inspect this diff.
@ -0,0 +160,4 @@
let mut subtags = raw.trim().split('-');
let language = subtags.next().unwrap_or("").to_lowercase();
let mut out = language;
if let Some(region) = subtags.next() {
Author
Owner

@⁠gut0to on GitHub · 2026-12-01 13:54 UTC · original · edited 2026-12-01 14:14 UTC

Could normalization preserve every valid BCP-47 subtag and apply casing per subtag? It only consumes the language and next subtag, so a custom tag such as zh-Hant-TW becomes zh-HANT and no longer matches zh-Hant-TW.toml as described for external BCP-47 catalogs. A round-trip test for a language-script-region tag would cover this. AI-assisted review: I used an AI assistant to inspect this diff.

**@⁠gut0to** on GitHub · 2026-12-01 13:54 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4913#discussion_r4755193965) · edited 2026-12-01 14:14 UTC Could normalization preserve every valid BCP-47 subtag and apply casing per subtag? It only consumes the language and next subtag, so a custom tag such as `zh-Hant-TW` becomes `zh-HANT` and no longer matches `zh-Hant-TW.toml` as described for external BCP-47 catalogs. A round-trip test for a language-script-region tag would cover this. AI-assisted review: I used an AI assistant to inspect this diff.
Author
Owner

@⁠gut0to on GitHub · 2026-12-01 13:54 UTC · original · reviewed

AI-assisted review: I used an AI assistant to inspect these changes; I checked each point against the implementation and tests.

**@⁠gut0to** on GitHub · 2026-12-01 13:54 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4913#pullrequestreview-6132656561) · **reviewed** AI-assisted review: I used an AI assistant to inspect these changes; I checked each point against the implementation and tests.
github-bot force-pushed github-bot/gh-4913 from 392a59f511 to 580a11dc81 2026-12-01 14:17:10 +00:00 Compare
Author
Owner

@⁠WanderLinks on GitHub · 2026-12-01 14:16 UTC · original

Thanks for the careful review, @⁠gut0to. All three points are addressed in the updated commit (force-pushed, still a single commit):

  1. build.rs — user locale files are no longer wiped. Removed remove_dir_all; copy_dir now only overwrites the bundled catalogs and leaves unrelated user-provided .toml files untouched. Verified by dropping a user file next to the executable and rebuilding — it survives.

  2. locale.rs — path traversal is rejected. Locale::from_str now rejects any code whose subtags are not ASCII-alphanumeric tokens joined by -, which rejects /, \, ., .., and empty subtags before a Custom is constructed. Added path_separators_and_invalid_subtags_are_rejected, covering ../outside, .., a/b, a\b, zh.CN, and zh--CN.

  3. locale.rs — full BCP-47 normalization. Normalization now walks every subtag and applies casing by position (lowercase language, title-case four-letter script, uppercase two-letter / three-digit region), retaining all subtags. zh-Hant-TW now round-trips (including zh-hant-tw input) and es-419 keeps its numeric region. Added language_script_region_round_trips_with_bcp47_casing.

Verification: 23 victory-i18n tests pass, rustfmt is clean, and clippy reports no warnings on the new code.

**@⁠WanderLinks** on GitHub · 2026-12-01 14:16 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4913#issuecomment-7313986880) Thanks for the careful review, @⁠gut0to. All three points are addressed in the updated commit (force-pushed, still a single commit): 1. **build.rs — user locale files are no longer wiped.** Removed `remove_dir_all`; `copy_dir` now only overwrites the bundled catalogs and leaves unrelated user-provided `.toml` files untouched. Verified by dropping a user file next to the executable and rebuilding — it survives. 2. **`locale.rs` — path traversal is rejected.** `Locale::from_str` now rejects any code whose subtags are not ASCII-alphanumeric tokens joined by `-`, which rejects `/`, `\`, `.`, `..`, and empty subtags before a `Custom` is constructed. Added `path_separators_and_invalid_subtags_are_rejected`, covering `../outside`, `..`, `a/b`, `a\b`, `zh.CN`, and `zh--CN`. 3. **`locale.rs` — full BCP-47 normalization.** Normalization now walks every subtag and applies casing by position (lowercase language, title-case four-letter script, uppercase two-letter / three-digit region), retaining all subtags. `zh-Hant-TW` now round-trips (including `zh-hant-tw` input) and `es-419` keeps its numeric region. Added `language_script_region_round_trips_with_bcp47_casing`. Verification: 23 `victory-i18n` tests pass, rustfmt is clean, and clippy reports no warnings on the new code.
github-bot closed this pull request 2026-12-01 18:30:34 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:28 UTC · original

Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:28 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4913#issuecomment-7321003772) Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!4914
No description provided.