feat(modapi): a mod adds a game language, a new choice of the Game language row played in one of the game's #2881

Merged
HumanBean merged 1 commit from HumanBean/Longshot:feat/game-languages into mod-api 2026-11-30 15:43:33 +00:00
Owner

Summary

A mod can now add a game language: a new choice on the Game language row (Gameplay tab), beside the game's 16,
with the game's own text translated. The ask came from the USenRT retranslation (an "English (Retranslation)" next to
ordinary English), but nothing here is specific to it.

[[gameLanguages]]
id   = "en-US-x-retold"     # a language code none of the game's has: what the settings keep
name = "English (Retold)"   # the row's choice
base = "en-US"              # the game's language it is played in

The texts are languages/<id>/<message file>.json, one JSON object of texts by label (the shape of longshot/i18n's
strings/<lang>.json), tags written as content.text writes them. No code and no permission.

Chosen, the next start:

  • tells the game the base (host/nn_applet.c asks the game side, hos_mod_language);
  • serves the base's text archive with the mod's texts in it: the language folder becomes texts patches made in
    memory, "replace": true (a label the game's file lacks is skipped and logged, never added), applied by the
    existing merged-file step and cached in modcache/.

Every other language, the base included, stays the game's. The settings keep the id, so an update keeps the choice.
If the mod is off, the game falls back to the id's first part when that is one of the game's (en-US-x-retold:
English (US)), else English (US). The setting is kept, so turning the mod back on brings the language back.

For a launcher: Longshot.exe --profile P --output json mod languages lists the row's choices: the game's 16, then
the languages the profile's mods add. The launcher change that uses it is a separate PR. A launcher that never asks
still shows the 16, as now.

Read first:

  • game/crates/api/src/game_languages.rs: the list, the code rule, the run's languages;
  • game/crates/api/src/loader/language.rs: the folder made into patches;
  • the game_init change in game/crates/longshot-game/src/lib.rs: the languages published after the scan, and the
    settings opened after them;
  • host/nn_applet.c;
  • docs/modding/i18n.md#game-languages.

Testing

Tested: Linux, RTX 3090, a pack on this PC's shared base, three headless runs from kokiri-start, with a local
pack of the USenRT retranslation (2,109 texts in 384 message files; it stays on this PC):

  • The mod's language chosen:
    • the log shows oe: language en-US-x-usenrt, a mod's, played in en-US and the mod's 384 texts patches;
    • the merged Mals/USen.Product.110.sarc.zs matches, message by message, the archive the retranslation's own
      repacker builds from the same game files, on 21,137 of 21,138 messages;
    • the one difference is the microphone hint, which Longshot rewords for the PC (the merge starts from that wording,
      as every texts patch does).
  • English (US) chosen, mod on: oe: language en-US; no texts patches applied.
  • The mod's language chosen, mod absent: ... is not one the game has, nor one a mod on adds: en-US; the setting
    is left as it is.
  • Checks: cargo test for content, api, modtool, longshot-game and build-driver; clippy and fmt; schema
    regenerated; tests/test_game_language.py, with new cases for a mod's language, its fallback, HOS_LANGUAGE and the
    renderer's Auto. nn_applet.c syntax-checks with llvm-mingw and Linux clang.

Still to test:

  • Any PC: open the Insert menu with the language chosen, expecting the Game language row to show its name. The control
    bridge's option get game_language reads 0 here for every language, a stock ja too, so it couldn't settle this
    (by hand).
  • Windows: one start with a mod's language chosen, expecting the same log lines (@Beanstalk).
  • A dialogue the retranslation changes, read in game (by hand).

Measurements

Nothing to measure for a player without a mod's language: no new work runs. With one chosen, the cost is the
merged-file step's existing work for one text archive (about 2.4 MB) at the first start, then the cached file. Not
timed here.

Risks

  • Mod-api only: the manifest field, "replace" on texts patches and mod languages are new API, so nothing
    shipped changes.
  • Settings order: the settings are opened slightly later in game_init (after the mod scan, still before the
    renderer loads). The host reads its language line from its own early copy, so it's unaffected.
  • A launcher with its own fixed list shows a mod language's id rather than its name until it asks mod languages.
  • To undo: a revert is enough.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit. (On mod-api, where the mod API lives.)
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named). (Only the touched crates' tests and
    test_game_language.py ran.)
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (Linux built; Windows syntax-checked only.)
  • Docs updated.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

https://claude.ai/code/session_016o1k1QvyUwMcv8kvCNXuco

## Summary A mod can now add a **game language**: a new choice on the Game language row (Gameplay tab), beside the game's 16, with the game's own text translated. The ask came from the USenRT retranslation (an "English (Retranslation)" next to ordinary English), but nothing here is specific to it. ```toml [[gameLanguages]] id = "en-US-x-retold" # a language code none of the game's has: what the settings keep name = "English (Retold)" # the row's choice base = "en-US" # the game's language it is played in ``` The texts are `languages/<id>/<message file>.json`, one JSON object of texts by label (the shape of `longshot/i18n`'s `strings/<lang>.json`), tags written as `content.text` writes them. No code and no permission. Chosen, the next start: - tells the game the base (`host/nn_applet.c` asks the game side, `hos_mod_language`); - serves the base's text archive with the mod's texts in it: the language folder becomes texts patches made in memory, `"replace": true` (a label the game's file lacks is skipped and logged, never added), applied by the existing merged-file step and cached in `modcache/`. Every other language, the base included, stays the game's. The settings keep the id, so an update keeps the choice. If the mod is off, the game falls back to the id's first part when that is one of the game's (`en-US-x-retold`: English (US)), else English (US). The setting is kept, so turning the mod back on brings the language back. **For a launcher:** `Longshot.exe --profile P --output json mod languages` lists the row's choices: the game's 16, then the languages the profile's mods add. The launcher change that uses it is a separate PR. A launcher that never asks still shows the 16, as now. Read first: - `game/crates/api/src/game_languages.rs`: the list, the code rule, the run's languages; - `game/crates/api/src/loader/language.rs`: the folder made into patches; - the `game_init` change in `game/crates/longshot-game/src/lib.rs`: the languages published after the scan, and the settings opened after them; - `host/nn_applet.c`; - `docs/modding/i18n.md#game-languages`. ## Testing **Tested:** Linux, RTX 3090, a pack on this PC's shared base, three headless runs from `kokiri-start`, with a local pack of the USenRT retranslation (2,109 texts in 384 message files; it stays on this PC): - **The mod's language chosen:** - the log shows `oe: language en-US-x-usenrt, a mod's, played in en-US` and the mod's 384 texts patches; - the merged `Mals/USen.Product.110.sarc.zs` matches, message by message, the archive the retranslation's own repacker builds from the same game files, on 21,137 of 21,138 messages; - the one difference is the microphone hint, which Longshot rewords for the PC (the merge starts from that wording, as every texts patch does). - **English (US) chosen, mod on:** `oe: language en-US`; no texts patches applied. - **The mod's language chosen, mod absent:** `... is not one the game has, nor one a mod on adds: en-US`; the setting is left as it is. - **Checks:** `cargo test` for content, api, modtool, longshot-game and build-driver; clippy and fmt; schema regenerated; `tests/test_game_language.py`, with new cases for a mod's language, its fallback, `HOS_LANGUAGE` and the renderer's Auto. `nn_applet.c` syntax-checks with llvm-mingw and Linux clang. **Still to test:** - Any PC: open the Insert menu with the language chosen, expecting the Game language row to show its name. The control bridge's `option get game_language` reads 0 here for every language, a stock `ja` too, so it couldn't settle this (by hand). - Windows: one start with a mod's language chosen, expecting the same log lines (`@Beanstalk`). - A dialogue the retranslation changes, read in game (by hand). ## Measurements Nothing to measure for a player without a mod's language: no new work runs. With one chosen, the cost is the merged-file step's existing work for one text archive (about 2.4 MB) at the first start, then the cached file. Not timed here. ## Risks - **Mod-api only:** the manifest field, `"replace"` on texts patches and `mod languages` are new API, so nothing shipped changes. - **Settings order:** the settings are opened slightly later in `game_init` (after the mod scan, still before the renderer loads). The host reads its language line from its own early copy, so it's unaffected. - **A launcher with its own fixed list** shows a mod language's id rather than its name until it asks `mod languages`. - **To undo:** a revert is enough. ## Checklist ### Ready for review - [ ] One topic, on current `main`; the title is a Conventional Commit. (On `mod-api`, where the mod API lives.) - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [ ] `mise run test` passes (any failure that also fails on `main` is named). (Only the touched crates' tests and `test_game_language.py` ran.) - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A check under `tests/` that reads changed source is updated, not weakened. - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (Linux built; Windows syntax-checked only.) - [x] Docs updated. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016o1k1QvyUwMcv8kvCNXuco
feat(modapi): a mod adds a game language, a new choice of the Game language row played in one of the game's (gameLanguages)
Some checks failed
PR description / Title and description (pull_request_target) Failing after 2s
3eaccf103f
A mod's manifest declares gameLanguages (id, name, base) and its folder's languages/<id>/<message file>.json holds the
texts by label. Chosen, the next start tells the game the base and serves the base's text archive with the mod's
texts in it (replace-only texts patches: a label the game's file lacks is not added); every other language stays the
game's. The settings keep the id, so an update keeps the choice; a mod off falls back to its code's first part.

- api::game_languages: the stock list, the code rule, the run's languages and the one played in;
- host/nn_applet.c asks the game side (hos_mod_language) of a code the game has not; hos_game_language_id;
- the Game language row lists the mods' after the game's 16 (Codec::Language by id); the settings are opened after
  the mods' languages are known, so the start's snapshot holds a mod language's value;
- texts patches take "replace": true; the merge takes a patch made in memory;
- mod check reads languages/; mod languages lists the row's choices for a launcher;
- docs/modding/i18n.md#game-languages; examples/new-language.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016o1k1QvyUwMcv8kvCNXuco
Author
Owner

Tested in game: Linux, RTX 3090, pack on the shared base, headless from kokiri-start with a local USenRT language mod: chosen, the host plays it in en-US and the merged USen archive matches the retranslation's own repacker on 21,137 of 21,138 messages (the one: the PC microphone rewording); English (US) chosen: stock; mod absent: falls back to en-US, setting kept.

**Tested in game:** Linux, RTX 3090, pack on the shared base, headless from kokiri-start with a local USenRT language mod: chosen, the host plays it in en-US and the merged USen archive matches the retranslation's own repacker on 21,137 of 21,138 messages (the one: the PC microphone rewording); English (US) chosen: stock; mod absent: falls back to en-US, setting kept.
Author
Owner
@review
HumanBean changed title from WIP: feat(modapi): a mod adds a game language, a new choice of the Game language row played in one of the game's to feat(modapi): a mod adds a game language, a new choice of the Game language row played in one of the game's 2026-11-30 15:01:57 +00:00
Author
Owner
@review
Author
Owner
@review
BeanBot left a comment

Recommendation: Approve. Some valid language files can lose translations when their generated patches exceed the parser's size limit. The menu can also use the wrong language when a mod language is selected through HOS_LANGUAGE. Nothing blocking is left: what remains is for the author before merging (below). Recommend approval; not approved on the forge.

Adds mod-provided game languages, exposes them to the menu and launcher, and merges their texts into the selected base archive. The design reuses the existing merge and cache, but large generated patches can be discarded and the player-facing path still needs in-game verification.

Should fix (2): not blocking, but worth doing before merging.

  • L1 game/crates/api/src/loader/language.rs:131: The patch size limit is calculated from unescaped input rather than the serialized JSON, and a single oversized operation is still emitted. (more on the line) Do: Bound patches using their serialized size, and report an individual operation that cannot fit rather than emitting a patch the merge will discard. Add cases with heavily escaped text and an oversized single text.
  • L2 gpu/vk/vk_menu_i18n.cpp:120: The renderer recognizes only stock codes in HOS_LANGUAGE, although the host now accepts mod language IDs. When: With HOS_LANGUAGE=fr-x-retold and a mod providing that language, the host starts the game in its declared base, but the menu's Auto language falls back to English instead of following the French code prefix. Do: Resolve mod language IDs for the renderer's startup language consistently with the documented Auto behavior, and cover the environment-variable path in the menu test.

Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)

  • L3: The visible language selection and translated dialogue have not yet been checked in a game run. When: The headless archive comparison does not exercise selecting the added choice in the Insert menu or displaying a changed dialogue. Do: On Linux, select the mod language in the Insert menu, restart, and check both the displayed choice and a translated dialogue.
  • L4: The new host and file-loading path has not been run on Windows. When: The reported Windows check is a syntax check, so it does not exercise startup, mod discovery and the merged archive on that platform. Do: Run a Windows start with a mod language selected and verify its choice and translated text, including a profile path containing non-ASCII characters.

@fix can do L1 and L2.

Checks: Failing on this head, which is behind its base, where it passes: PR description / Title and description (pull_request_target). @rebase (or @fix) brings it up to date and runs it again; not held against it.

More: does it help, other systems, switches, what was read

Does it help: Unproven as a player-facing feature: the reported Linux headless run matched 21,137 of 21,138 archive messages, with the remaining difference attributed to Longshot's microphone wording. The menu choice and translated dialogue have not yet been verified in game; no timing was reported.

Other systems: The change affects startup language selection, settings persistence, text archive merging and caching, the menu's automatic language, packaged mods, and the launcher-facing CLI on Windows and Linux. The reported run covers Linux with an NVIDIA GPU; the PR reports no Windows game run or visible menu and dialogue check.

Switches: HOS_LANGUAGE is extended to accept mod language IDs; it remains unset by default. No new switch is added.

Reviewed: 3eaccf103f against cb37f5ab8a: Read the repository's AGENTS.md, CONTRIBUTING.md and pull request template, the commit and the changes to the language loader, manifest, merge path, settings, host, menu, CLI and documentation. Inspected surrounding startup, settings and cache paths. Skimmed the generated schema, recorded test additions and example files; did not read every changed file in full. docs/review-checklist.md was absent.; nothing run (a code review).

Checked and fine:

  • The commit records AI assistance with a Co-Authored-By trailer.
  • The example identifies its labels as made up; the reported game-derived archive remains local.
  • The generated patch bytes participate in the merged-file cache key.
  • The published language lists and active ID use locks.

Testing: No code, tests, builds or project scripts were run, as requested. The PR reports a Linux headless archive comparison and touched-crate checks; the CI data lists no failure unique to this head.

Overlaps and merge order: Not checked; the network is closed.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Approve.** Some valid language files can lose translations when their generated patches exceed the parser's size limit. The menu can also use the wrong language when a mod language is selected through HOS_LANGUAGE. Nothing blocking is left: what remains is for the author before merging (below). Recommend approval; not approved on the forge. Adds mod-provided game languages, exposes them to the menu and launcher, and merges their texts into the selected base archive. The design reuses the existing merge and cache, but large generated patches can be discarded and the player-facing path still needs in-game verification. **Should fix (2)**: not blocking, but worth doing before merging. - **L1** `game/crates/api/src/loader/language.rs:131`: The patch size limit is calculated from unescaped input rather than the serialized JSON, and a single oversized operation is still emitted. (more on the line) **Do:** Bound patches using their serialized size, and report an individual operation that cannot fit rather than emitting a patch the merge will discard. Add cases with heavily escaped text and an oversized single text. - **L2** `gpu/vk/vk_menu_i18n.cpp:120`: The renderer recognizes only stock codes in HOS_LANGUAGE, although the host now accepts mod language IDs. *When:* With HOS_LANGUAGE=fr-x-retold and a mod providing that language, the host starts the game in its declared base, but the menu's Auto language falls back to English instead of following the French code prefix. **Do:** Resolve mod language IDs for the renderer's startup language consistently with the documented Auto behavior, and cover the environment-variable path in the menu test. **Testing before merging (2)** (runs on the systems it can change; it doesn't hold the recommendation) - **L3**: The visible language selection and translated dialogue have not yet been checked in a game run. *When:* The headless archive comparison does not exercise selecting the added choice in the Insert menu or displaying a changed dialogue. **Do:** On Linux, select the mod language in the Insert menu, restart, and check both the displayed choice and a translated dialogue. - **L4**: The new host and file-loading path has not been run on Windows. *When:* The reported Windows check is a syntax check, so it does not exercise startup, mod discovery and the merged archive on that platform. **Do:** Run a Windows start with a mod language selected and verify its choice and translated text, including a profile path containing non-ASCII characters. `@fix` can do L1 and L2. **Checks:** Failing on this head, which is behind its base, where it passes: `PR description / Title and description (pull_request_target)`. `@rebase` (or `@fix`) brings it up to date and runs it again; not held against it. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven as a player-facing feature: the reported Linux headless run matched 21,137 of 21,138 archive messages, with the remaining difference attributed to Longshot's microphone wording. The menu choice and translated dialogue have not yet been verified in game; no timing was reported. **Other systems:** The change affects startup language selection, settings persistence, text archive merging and caching, the menu's automatic language, packaged mods, and the launcher-facing CLI on Windows and Linux. The reported run covers Linux with an NVIDIA GPU; the PR reports no Windows game run or visible menu and dialogue check. **Switches:** HOS_LANGUAGE is extended to accept mod language IDs; it remains unset by default. No new switch is added. **Reviewed:** 3eaccf103fa4 against cb37f5ab8a63: Read the repository's AGENTS.md, CONTRIBUTING.md and pull request template, the commit and the changes to the language loader, manifest, merge path, settings, host, menu, CLI and documentation. Inspected surrounding startup, settings and cache paths. Skimmed the generated schema, recorded test additions and example files; did not read every changed file in full. docs/review-checklist.md was absent.; nothing run (a code review). **Checked and fine:** - The commit records AI assistance with a Co-Authored-By trailer. - The example identifies its labels as made up; the reported game-derived archive remains local. - The generated patch bytes participate in the merged-file cache key. - The published language lists and active ID use locks. **Testing:** No code, tests, builds or project scripts were run, as requested. The PR reports a Linux headless archive comparison and touched-crate checks; the CI data lists no failure unique to this head. **Overlaps and merge order:** Not checked; the network is closed. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
@ -0,0 +128,4 @@
if ops.len() >= LABELS || bytes + label.len() + t.len() > BYTES {
flush(&mut ops, &mut out);
bytes = 0;
}
Member

L1 (should fix): The patch size limit is calculated from unescaped input rather than the serialized JSON, and a single oversized operation is still emitted.

When: A language file under the 8 MiB file limit can contain enough quotes, backslashes or newlines that a generated patch exceeds 1 MiB. The merge step rejects that entire patch, so otherwise valid translations in it remain in the base language.

Do: Bound patches using their serialized size, and report an individual operation that cannot fit rather than emitting a patch the merge will discard. Add cases with heavily escaped text and an oversized single text.

**L1** (should fix): The patch size limit is calculated from unescaped input rather than the serialized JSON, and a single oversized operation is still emitted. *When:* A language file under the 8 MiB file limit can contain enough quotes, backslashes or newlines that a generated patch exceeds 1 MiB. The merge step rejects that entire patch, so otherwise valid translations in it remain in the base language. **Do:** Bound patches using their serialized size, and report an individual operation that cannot fit rather than emitting a patch the merge will discard. Add cases with heavily escaped text and an oversized single text.
HumanBean force-pushed feat/game-languages from 3eaccf103f
Some checks failed
PR description / Title and description (pull_request_target) Failing after 2s
to 0333fafcad
Some checks failed
PR description / Title and description (pull_request_target) Failing after 16s
2026-11-30 15:40:58 +00:00
Compare
HumanBean force-pushed feat/game-languages from 0333fafcad
Some checks failed
PR description / Title and description (pull_request_target) Failing after 16s
to 5e3c911019
Some checks failed
PR description / Title and description (pull_request_target) Failing after 7s
2026-11-30 15:41:36 +00:00
Compare
Author
Owner

Review fixes, folded into the commit (now 5e3c9110):

  • L1: fixed, and wider than reported. A language file's texts are now bounded as written, with escapes counted. Each text is also read alone by the patch reader before it goes into a patch. Patches were never at risk of the 1 MiB limit (they're cut at 600 KiB), but a single text the reader refuses, over 16 KiB or holding a control character, would have taken its whole patch file with it. Such a text is now left out with its reason: the log says it, and mod check reports it as an error. Two new tests: heavily escaped texts that fit unescaped but not as written, and a text the reader refuses.
  • L2: fixed. The renderer reads HOS_LANGUAGE the same way it reads the settings' line, falling back to the code's first part when that is a language the game has (fr-x-retold gives fr). tests/test_game_language.py has a new case for this.
  • L3 / L4: still open (Insert menu by hand, and a Windows start), listed under Still to test.

Checks: cargo test for api's loader::language and modtool, clippy -D warnings, fmt and tests/test_game_language.py all pass. The one modtool failure, "Game queue priority" untranslated, is on the base too (fixed on main by #2861).

Review fixes, folded into the commit (now 5e3c9110): - **L1:** fixed, and wider than reported. A language file's texts are now bounded as written, with escapes counted. Each text is also read alone by the patch reader before it goes into a patch. Patches were never at risk of the 1 MiB limit (they're cut at 600 KiB), but a single text the reader refuses, over 16 KiB or holding a control character, would have taken its whole patch file with it. Such a text is now left out with its reason: the log says it, and `mod check` reports it as an error. Two new tests: heavily escaped texts that fit unescaped but not as written, and a text the reader refuses. - **L2:** fixed. The renderer reads `HOS_LANGUAGE` the same way it reads the settings' line, falling back to the code's first part when that is a language the game has (`fr-x-retold` gives `fr`). `tests/test_game_language.py` has a new case for this. - **L3 / L4:** still open (Insert menu by hand, and a Windows start), listed under Still to test. Checks: `cargo test` for api's loader::language and modtool, clippy `-D warnings`, fmt and `tests/test_game_language.py` all pass. The one modtool failure, "Game queue priority" untranslated, is on the base too (fixed on main by #2861).
HumanBean merged commit 75bcd270db into mod-api 2026-11-30 15:43:33 +00:00
HumanBean deleted branch feat/game-languages 2026-11-30 15:43:34 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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
MagicBeanDev/Longshot!2881
No description provided.