Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@VirenMohindra
Copy link
Contributor

@VirenMohindra VirenMohindra commented Dec 12, 2025

summary

  • adds localization support for the system tray menu (settings, check for updates, quit, cancel)
  • tray menu updates immediately when app language is changed in settings (no restart required)
  • uses the same translation json files as the frontend (single source of truth)
  • supports 9 languages: english, spanish, french, vietnamese, german, japanese, chinese, italian, polish

technical details

  • build.rs auto-generates tray translations at compile time from frontend locale files
  • struct fields derived from english json keys (camelCase → snake_case)
  • languages auto-discovered from src/i18n/locales/ directory - no code changes needed for new locales
  • locales without a "tray" section are skipped gracefully (falls back to english)
  • uses existing tauri-plugin-os::locale() for os locale detection
  • language priority: app setting → os locale → english fallback
en fr

test plan

  • verify tray displays correct language based on app setting
  • verify tray updates immediately when changing language (no restart)
  • verify fallback to os locale when app language is "auto"
  • verify fallback to english for unsupported locales
  • test all 9 supported languages (en, es, fr, vi, de, ja, zh, it, pl)

@VirenMohindra VirenMohindra force-pushed the feat/tray-menu-localization-v2 branch 2 times, most recently from af786c1 to 9cd869b Compare December 12, 2025 13:58
@cjpais
Copy link
Owner

cjpais commented Dec 12, 2025

ah nice i was going to do this in a second pass on localization so thank you

only request is don't add a new dep and instead use tauri-os built in

https://docs.rs/tauri-plugin-os/latest/tauri_plugin_os/fn.locale.html

it would be good if it didn't require an app restart, but its okay for now. there might be a function already to refresh the tray, so that might need to be run when the setting changes

@VirenMohindra VirenMohindra force-pushed the feat/tray-menu-localization-v2 branch 5 times, most recently from 69b288d to 571b24e Compare December 14, 2025 17:04
- add tray_i18n.rs module for tray menu translations
- load translations from shared frontend JSON files at compile time
- support 7 languages: en, es, fr, vi, de, ja, zh
- add tray section to de, ja, zh translation files
- use tauri-plugin-os::locale() for system locale detection
- add refresh_tray_locale command for live tray updates
- update AppLanguageSelector to refresh tray on language change
- tray menu now updates immediately when app language changes
- remove CLAUDE.md from repository
@VirenMohindra VirenMohindra force-pushed the feat/tray-menu-localization-v2 branch from 571b24e to 62cbe71 Compare December 14, 2025 17:05
@VirenMohindra
Copy link
Contributor Author

only request is don't add a new dep and instead use tauri-os built in

done! now using tauri_plugin_os::locale()

it would be good if it didn't require an app restart

i looked into this and also managed to refresh the cart on lang change, the function helped

also added tray translations for german, japanese, and chinese (the new languages from #444)

"vi" => "../../src/i18n/locales/vi/translation.json",
"de" => "../../src/i18n/locales/de/translation.json",
"ja" => "../../src/i18n/locales/ja/translation.json",
"zh" => "../../src/i18n/locales/zh/translation.json",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mapping feels like it should not be hardcoded and should be imported from a config file or inferred from file paths?

Ignore me if there's a good reason for not doing this tho.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in... the need to say

//! NOTE: When adding a new language to the frontend (src/i18n/locales/),
//! remember to also add it to the load_translations! macro below.

feels like a smell here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the constraint here is rust's include_str! macro - it requires compile-time string literals, so there's no way to dynamically discover files without either~

  1. a build.rs script that scans the locales directory and generates the mapping
  2. a procedural macro that reads the filesystem at compile time

both add complexity that felt like overkill for just seven languages. the explicit list has the benefit of compile-time safety (missing file equals build error) and the NOTE comment documents the manual step

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think build.rs script might be most appropriate just to reduce complications for new contributors. It would probably be a write once and forget about it forever piece of code which is probably a good thing. I don't think a comment is sufficient for new contributors if they haven't read the code at all. This either needs to be documented in a README or similar, or some alternative approach.

I'll have a think about the best way to approach this problem as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can get a start on build.rs and push it in in a sec

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added -- let me know if this works!

@dannysmith
Copy link
Collaborator

Note to self for when I'm on a machine where I can build/run this:

  1. How will this code behave when the language is set to a language not supported by tray_i18n.rs.
  2. How will this code behave if the relevant translation.json does not contain the required translations?

@cjpais
Copy link
Owner

cjpais commented Dec 15, 2025

Another misc comment is we almost certainly need to have a setting for the UI language to be persisted in the settings file itself. I believe right now it's a local-storage value in the browser (which is definitely a hack imo). We probably should remove that in favor of a json stored string, so that the backend and frontend can both have a good source of truth for the language.

In regards to the auto detection of the language, I'm not 100% the best way of going about that. Since it would either need an 'auto' setting itself, or something like en-auto to signify somewhere that this was an auto-picked language code. I forget if this code has it specifically, but since it's using a way to get the locale it probably is. Possibly we just drop support for auto-detection of locale and force an explicit pick?

@cjpais
Copy link
Owner

cjpais commented Dec 16, 2025

@VirenMohindra when/if you get a chance can you merge with main, I took care of the using the settings file. There should be an appropriate setting to be able to pull from on the rust side. Would guess it will even clean up the implementation a bit

@VirenMohindra
Copy link
Contributor Author

@VirenMohindra when/if you get a chance can you merge with main, I took care of the using the settings file

yeah thank you! will do right now. the build.rs implementation took a bit and wanted to land that to get some eyes on it before pinging ya

@cjpais
Copy link
Owner

cjpais commented Dec 16, 2025

thank you! no worries, just excited to get this one in :)

@cjpais cjpais merged commit bfca46f into cjpais:main Dec 18, 2025
2 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.

3 participants