feat(i18n): localization foundation and language picker - #57
Open
noahbclarkson wants to merge 1 commit into
Open
feat(i18n): localization foundation and language picker#57noahbclarkson wants to merge 1 commit into
noahbclarkson wants to merge 1 commit into
Conversation
Adds `rgitui_i18n` and wires it into settings, so a language can be chosen and applied without a restart. This is the infrastructure only — the Appearance settings panel is converted as the working example; the other ~1500 user-facing strings are still English literals. English is the source of truth in `src/en.rs` rather than a JSON asset, for the same reason the built-in themes are Rust: it is always present and cannot drift, so any missing translation has something to fall back to. Translations are JSON under `assets/locales/`, embedded at build time, with user overrides from the config directory so a translator can iterate against a release build. The catalogue is a process-wide RwLock rather than a GPUI global, because error strings are built on background threads and need translating too. The tradeoff is that GPUI cannot know a language change dirties the frame, so `set_language` must be followed by `cx.refresh_windows()`. `t!` and `tp!` return `SharedString`, which every `rgitui_ui` builder already accepts — converting a call site is a one-line change. Locale files are validated by tests: unknown keys fail (they would silently never render), placeholders must survive translation, and plural forms must be declared in pairs. Missing keys are deliberately allowed so partial translations are worth shipping. Simplified Chinese ships as the first translation and needs native review. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
@noahbclarkson I'm a native Simplified Chinese speaker — happy to review, done. The translation is in good shape: terminology is consistent (Appearance = 外观, One suggestion, purely idiomatic polish (not a bug): Two things worth flagging from your own "Known gaps" section, since they hit
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Foundation for #55. This is steps 1–2 of the plan on that issue: the i18n crate
and the language setting. It deliberately does not convert the rest of the
UI — that is the follow-up work, and it is mechanical once this lands.
What works now
locale found, each labelled in its own script, with a count of how many strings
it still leaves untranslated.
settings.jsonfiles, which have no
languagekey and default tosystem.is still English literals.
Design
English is Rust, translations are JSON.
crates/rgitui_i18n/src/en.rsis thesource of truth — same reasoning as
rgitui_theme::builtin_themes: it is alwayspresent and cannot drift from an asset file, so every missing translation has
something to fall back to. Translations live in
assets/locales/*.json, embeddedat build time, with user overrides from
<config>/rgitui/locales/so atranslator can iterate against a release build without rebuilding.
t!returnsSharedString. Everyrgitui_uibuilder already takesimpl Into<SharedString>, so converting a call site is a one-line change with noAPI churn:
The catalogue is a process-wide
RwLock, not a GPUI global. Error messagesare built on background threads and will need translating too, and a GPUI global
is unreachable from there. The cost is that GPUI cannot know a language change
dirties the frame, so
set_languagemust be followed bycx.refresh_windows();this is documented at both ends and is the only manual step callers have.
Plural support is in from the start —
tp!("key", count)selects a.one/.otherform under the locale's declared rule (one_other,zero_one_other,other_only). Retrofitting this later would have meantrevisiting every count-bearing string a second time.
What the tests enforce
cargo test -p rgitui_i18n(35 tests) validates every file inassets/locales/:en.rsis a typo or a leftoverfrom a deleted message, and would silently never render.
{count}, thetranslation must too. Surrounding text may be reordered freely.
partial translation is worth shipping — that is the whole contribution model.
stay readable.
Verified
cargo fmt --check,cargo clippy --workspace --all-targets -D warnings, andcargo test --workspaceall pass. Booted the app and confirmed the bundledlocale loads and that
systemand an explicitzh-CNboth resolve as intended.I did not visually confirm the Chinese UI renders — see below.
Known gaps, for follow-ups
assets/fonts/has IBM Plex Sans, JetBrainsMono and Lilex; Chinese depends on system font fallback. Untested on all three
platforms, and may need a per-locale default
ui_font.plausible UI vocabulary, not verified. @aiysya, if you are up for it, this is a
small file and your read on it would be worth a lot.
anyhow!sites inrgitui_gitrun on background threads and feed 95show_toastcalls. Theright move is typed error variants translated at the toast boundary, not
t!scattered through the git layer. Separate PR.
format_relative_timeinrgitui_graph/src/lib.rsbuilds"{}h ago"by hand.English; the fixed
author_column_width/date_column_widthdefaults and thesidebar buttons have not been checked against that.
Closes nothing yet — #55 stays open until the UI is actually converted.
🤖 Generated with Claude Code