Skip to content

[codex] Add localization support and Chinese translation - #227

Open
5151561 wants to merge 6 commits into
Wet-Boys:mainfrom
5151561:feature/lookingglass-i18n
Open

[codex] Add localization support and Chinese translation#227
5151561 wants to merge 6 commits into
Wet-Boys:mainfrom
5151561:feature/lookingglass-i18n

Conversation

@5151561

@5151561 5151561 commented May 17, 2026

Copy link
Copy Markdown

Summary

This PR adds localization support for LookingGlass-owned UI text and ships an initial Chinese translation.

  • Adds a LookingGlass language API backed by bundled JSON language files.
  • Adds English and Simplified Chinese resources under LookingGlass/Languages.
  • Localizes LookingGlass hardcoded panel text, config names/descriptions/categories, RiskOfOptions labels, stats display templates, portal text, item stat labels, buff descriptions, and skill proc extra info.
  • Keeps game-provided content following the game language while localizing LookingGlass-added UI.
  • Preserves user-customized stats display strings and only migrates known built-in default templates.
  • Adds language aliases such as schinese, zh, and zh_CN for Chinese language resolution.
  • Includes language resources in the Thunderstore package.
  • Adds a localization validation script to catch missing tokens, malformed style tags, and untranslated zh-CN duplicates.

How It Works

The implementation adds LookingGlassLanguageAPI as a small localization layer for text owned by LookingGlass itself.

  • Language files live at LookingGlass/Languages/{languageName}/LookingGlass.json and use stable LG_TOKEN_* keys.
  • LookingGlassLanguageAPI.Init(...) registers the bundled Languages root with RoR2 through Language.collectLanguageRootFolders, so the game can load the same token set through its normal language system.
  • Code calls helpers such as GetString, ConfigName, ConfigDescription, ConfigCategory, and item/stat label helpers instead of hardcoding user-facing English text.
  • Runtime lookup first tries the current game language, then falls back to the bundled English resource, then to the original fallback string. This keeps missing translations safe instead of breaking the UI.
  • Existing game content still uses the original RoR2 language tokens, so vanilla/game-provided content continues to follow the selected game language normally.
  • RiskOfOptions needs extra handling because it caches option/category/dropdown tokens internally. This PR refreshes those RiskOfOptions language entries when the current language changes, including enum dropdown choices.
  • Stats Display templates are special because their default strings are stored in BepInEx config. The migration only rewrites values that exactly match a known built-in default in any bundled language, so customized user templates are preserved.

Why This Supports Multiple Languages

The code no longer depends on Chinese-specific replacements. It resolves text through language tokens and language folders, with English as the fallback language. zh-CN is just the first non-English language folder shipped with the mod.

Adding another language does not require changing every UI call site again. New translations can provide the same LG_TOKEN_* keys under another language folder, and the runtime will select that folder when RoR2 reports the matching language name.

Adding Another Language

To adapt another language, for example Japanese:

  1. Copy LookingGlass/Languages/en/LookingGlass.json to LookingGlass/Languages/ja/LookingGlass.json.
  2. Keep every JSON key unchanged and translate only the values.
  3. Add the new language folder to the Thunderstore copy list so it is packaged with the mod.
  4. If RoR2 reports a different language name than the folder name, add an alias in LookingGlassLanguageAPI.languageAliases.
  5. Run bash scripts/validate-localization.sh and build the package.
  6. Test in-game with that language selected, especially the Stats Display panel and RiskOfOptions config page.

Chinese Support

The PR includes a zh-CN translation for the added LookingGlass UI, including the Stats Display panel and the Stats Display options page. The implementation was manually tested in a Chinese game environment, including the previously problematic options page text and dropdown choices.

AI Assistance Disclosure

This change was implemented and reviewed with AI assistance from Codex. Final behavior was manually checked by the maintainer/user in-game.

Validation

  • bash scripts/validate-localization.sh
  • dotnet build LookingGlass.sln --configuration Debug
  • dotnet build LookingGlass.sln --configuration Release
  • Confirmed release package contains LookingGlass.dll and both Languages/en/LookingGlass.json and Languages/zh-CN/LookingGlass.json
  • Manual in-game check in Chinese language mode

Notes

The build still reports the existing project warnings for deprecated RoR2 APIs and unused fields; no new build errors were introduced.

@5151561
5151561 marked this pull request as ready for review May 17, 2026 20:24
@5151561

5151561 commented May 26, 2026

Copy link
Copy Markdown
Author

@ToastedOven
Hi! I opened this PR about a week ago and wanted to check if it might have been missed due to org notifications. When you have time, could you take a look? Thanks!

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