feat(modapi): a mod adds a game language, a new choice of the Game language row played in one of the game's #2881
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2881
Loading…
Reference in a new issue
No description provided.
Delete branch "HumanBean/Longshot:feat/game-languages"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
The texts are
languages/<id>/<message file>.json, one JSON object of texts by label (the shape oflongshot/i18n'sstrings/<lang>.json), tags written ascontent.textwrites them. No code and no permission.Chosen, the next start:
host/nn_applet.casks the game side,hos_mod_language);memory,
"replace": true(a label the game's file lacks is skipped and logged, never added), applied by theexisting 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 languageslists the row's choices: the game's 16, thenthe 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;game_initchange ingame/crates/longshot-game/src/lib.rs: the languages published after the scan, and thesettings 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 localpack of the USenRT retranslation (2,109 texts in 384 message files; it stays on this PC):
oe: language en-US-x-usenrt, a mod's, played in en-USand the mod's 384 texts patches;Mals/USen.Product.110.sarc.zsmatches, message by message, the archive the retranslation's ownrepacker builds from the same game files, on 21,137 of 21,138 messages;
as every texts patch does).
oe: language en-US; no texts patches applied.... is not one the game has, nor one a mod on adds: en-US; the settingis left as it is.
cargo testfor content, api, modtool, longshot-game and build-driver; clippy and fmt; schemaregenerated;
tests/test_game_language.py, with new cases for a mod's language, its fallback,HOS_LANGUAGEand therenderer's Auto.
nn_applet.csyntax-checks with llvm-mingw and Linux clang.Still to test:
bridge's
option get game_languagereads 0 here for every language, a stockjatoo, so it couldn't settle this(by hand).
@Beanstalk).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
"replace"on texts patches andmod languagesare new API, so nothingshipped changes.
game_init(after the mod scan, still before therenderer loads). The host reads its language line from its own early copy, so it's unaffected.
mod languages.Checklist
Ready for review
main; the title is a Conventional Commit. (Onmod-api, where the mod API lives.)mise run testpasses (any failure that also fails onmainis named). (Only the touched crates' tests andtest_game_language.pyran.)main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
https://claude.ai/code/session_016o1k1QvyUwMcv8kvCNXuco
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.
@review
WIP: feat(modapi): a mod adds a game language, a new choice of the Game language row played in one of the game'sto feat(modapi): a mod adds a game language, a new choice of the Game language row played in one of the game's@review
@review
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.
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.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)
@fixcan 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:
3eaccf103fagainstcb37f5ab8a: 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:
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.
@ -0,0 +128,4 @@if ops.len() >= LABELS || bytes + label.len() + t.len() > BYTES {flush(&mut ops, &mut out);bytes = 0;}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.
3eaccf103f0333fafcad0333fafcad5e3c911019Review fixes, folded into the commit (now
5e3c9110):mod checkreports it as an error. Two new tests: heavily escaped texts that fit unescaped but not as written, and a text the reader refuses.HOS_LANGUAGEthe 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-retoldgivesfr).tests/test_game_language.pyhas a new case for this.Checks:
cargo testfor api's loader::language and modtool, clippy-D warnings, fmt andtests/test_game_language.pyall pass. The one modtool failure, "Game queue priority" untranslated, is on the base too (fixed on main by #2861).