CompactGUI icon indicating copy to clipboard operation
CompactGUI copied to clipboard

feat: Add multi-language support (i18n) via JSON config

Open ShadowLoveElysia opened this issue 1 month ago • 6 comments

Hi! I implemented a translation system for CompactGUI.

It works by scanning the UI at runtime and replacing text using JSON files, so I didn't have to change your existing hardcoded strings (safe and clean).

What's new:

  • Auto-detects system language on first run.
  • Automatically switch the displayed language when changing the language (only for ComboBoxItem)
  • Added a Language Selector in the Settings page.
  • Added localization files for Chinese, Japanese, German, French, etc. in the i18n folder.
  • Translations are fully external (JSON), easy for others to contribute.

🐛 One small heads-up (Help Needed): The "View on GitHub" button currently disappears when the translation logic runs. I suspect my reflection code is accidentally overwriting the button's complex content (Icon + Text) with a simple string. I'm not sure how to fix this specific button without breaking the loop, so I might need your help on that part! 😅

Hope this helps more people use this tool!

This is the modified interface and effect I have created. image image image

ShadowLoveElysia avatar Nov 23 '25 19:11 ShadowLoveElysia

Nice work! One concern: the reflection-based approach using original text as keys feels fragile (some controls get overwritten, changes to wording break translations).

Would you (and the original author) be open to moving toward stable keys and a standard i18n pattern (resource dictionaries) in the future? If so, I’m happy to help flesh it out. 👀

panda361 avatar Nov 25 '25 08:11 panda361

Nice work! One concern: the reflection-based approach using original text as keys feels fragile (some controls get overwritten, changes to wording break translations).

Would you (and the original author) be open to moving toward stable keys and a standard i18n pattern (resource dictionaries) in the future? If so, I’m happy to help flesh it out. 👀

At first, I also wanted to try the separation. However, after I did it myself, I found that there would be a bunch of problems during the compilation. The current version is the result of my trade - offs, and it seems to be working quite well at present.🤔

ShadowLoveElysia avatar Nov 25 '25 09:11 ShadowLoveElysia

Love this, and so much easier than going through the hassle of resource dictionary setups!

Iridium-IO avatar Nov 27 '25 06:11 Iridium-IO

Love this, and so much easier than going through the hassle of resource dictionary setups!

However, it is worth noting that reflection based translation requires simultaneous modification/addition of the corresponding English/other language in the JSON whenever the string is changed

ShadowLoveElysia avatar Nov 27 '25 09:11 ShadowLoveElysia

Love this, and so much easier than going through the hassle of resource dictionary setups!

Apart from adding the corresponding English and translation to JSON every time a new string is added, there are no other requirements

ShadowLoveElysia avatar Nov 27 '25 09:11 ShadowLoveElysia

Nice work! One concern: the reflection-based approach using original text as keys feels fragile (some controls get overwritten, changes to wording break translations). Would you (and the original author) be open to moving toward stable keys and a standard i18n pattern (resource dictionaries) in the future? If so, I’m happy to help flesh it out. 👀

At first, I also wanted to try the separation. However, after I did it myself, I found that there would be a bunch of problems during the compilation. The current version is the result of my trade - offs, and it seems to be working quite well at present.🤔

Makes sense. If there’s no big refactor planned, the current approach works efficiently enough. 🚀

panda361 avatar Nov 27 '25 15:11 panda361