Skip to content

String it on Unity: retranslate what XUnity captured with the app's AI - #252

Merged
rouges78 merged 1 commit into
mainfrom
string-it-xunity-ai
Nov 25, 2026
Merged

rouges78 merged 1 commit into
mainfrom
string-it-xunity-ai

Conversation

@rouges78

Copy link
Copy Markdown
Owner

On Unity games without localization tables, String it installs BepInEx + XUnity, and XUnity translates with Google rather than the app's AI chain. This makes String it a two-step flow:

  1. First press: installs XUnity, as it does today. The step's message now says to play for a while and then press String it again.
  2. Second press on the same game and language: XUnity is already installed, so nothing is reinstalled. The app reads every text XUnity captured, translates the whole set in batches with the AI chain (memory, glossary, profile) and writes the results to BepInEx/Translation/{lang}/Text/{Game}.txt. XUnity's README says its own _AutoGeneratedTranslations.txt "will always have the lowest priority", so our file takes precedence. A text the AI does not translate keeps Google's translation. If nothing has been captured yet, the button says to play first.

XUnity file format fix

read_captured_translations split each line at the first =, escaped or not. That sent multi-line texts to the AI with literal \n sequences. write_translation_file wrote values without encoding them, so a newline in a translation broke the line. Both now follow XUnity's own TextHelper.Encode / ReadTranslationLineAndDecode rules. This also fixes the existing "Migliora con AI" button, which uses the same two commands.

Why two steps and not the live bridge

XUnity sends one text per request, one request at a time, and shuts itself down after five empty responses in a row. Live AI per string would be slow and fragile on free providers. The two-step flow translates in batches of 20 and doesn't need the app running while the game is played. Static extraction before playing wasn't an option either: Mouthwashing keeps its dialogue in Languages/*.dat, which the game loads at runtime. The full write-up is in docs/METODI-DI-TRADUZIONE.md.

Checks

  • Rust: unit tests for encode/decode, plus real_xunity_files_round_trip (ignored, read-only) on the 7 XUnity capture files on disk: 12,330 lines, all read, all rewritten byte for byte, none dropped.
  • Vitest: __tests__/lib/string-it-xunity-ai.test.ts (5 tests). typecheck, i18n:check and eslint are clean (only pre-existing warnings).
  • New strings are in all 12 locales.

Not verified

  • The full flow from the button (two presses, real AI) has not been run.
  • Nobody has checked in game that the AI file overrides Google's. The precedence comes from XUnity's README, not from a test.
  • IL2CPP games (BepInEx 6) are untested.

🤖 Generated with Claude Code

On Unity games without localization tables String it installs XUnity, which
translates with Google instead of the app's AI chain. Pressing String it again
on the same game and language now reads every text XUnity captured, translates
them in batches with the AI chain (memory, glossary, profile) and writes them
to a translation file that XUnity prefers over its own Google output.

XUnity's file format was read wrongly: lines were split at the first '='
even when escaped, and multi-line texts reached the AI with literal '\n'.
Reading and writing now follow XUnity's own encoding. Checked read-only on
the 12,330 lines of the seven XUnity capture files on disk: all read, all
rewritten byte for byte.

Not yet run end to end from the button, nor looked at in game.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rouges78
rouges78 merged commit 85ccbca into main Nov 25, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant