Conversation
Cross-platform i18n: the Web build and the Tauri webview share one
react-i18next runtime-switching setup. Reject Next.js [lang] routing
(static export forbids Proxy/redirects/cookies) in favor of pure
client-side runtime detection, matching native desktop UX (Typora/VSCode).
- Add common/i18n/: i18next singleton + I18nProvider (switch-after-mount to
avoid hydration mismatch) + useLocale hook + config (localStorage >
navigator detection) + locales/{en,zh,ja}.json (structurally identical)
- Add a DaisyUI language switcher in the landing nav
- Wire editor/updater/chat/playground/landing/save-document/errors (~60
hardcoded strings); components use useTranslation, non-component modules
use i18n.t
- Keep shared packages pure: @do-md/* pull in no i18n library
- Extract landing server-component nav/footer into client components
Verified: tsc clean on changed files; SSR renders no raw keys; browser
auto-switches to the system locale with no hydration or console errors.
@do-md/core-react is a published npm package whose ::after content text is
baked into its shipped CSS. Adding CSS custom-property hooks upstream would
need a release, so override the content at the app level, keyed on the
html[lang] attribute that I18nProvider keeps in sync with the active locale.
Finding: the code-block copy button ("Copy code"/"Copied!") is icon-only in
the shipped package - dead CSS (the nested :after resolves to a descendant
of an empty div and renders nothing). Overriding it would add phantom text
that the English UI never shows, so we deliberately do not. Only the
genuinely-visible "Toggle"/"Empty toggle" placeholders are localized.
Confirmed via browser getComputedStyle.
The native layer reuses the same translation source: Rust embeds locales/*.json via include_str! and reads the menu.* namespace, so React and Rust share one dictionary (one source, two consumers). - Cargo: add sys-locale for system-language detection - lib.rs: menu_i18n module (normalize / system_locale / t) + build_app_menu (generic, reused by setup and the set_locale command) + get_system_locale and set_locale commands. The menu is built from the system locale at launch; item ids stay stable so the single on_menu_event handler survives a rebuild - frontend: syncNativeLocale invokes set_locale under Tauri to rebuild the native menu; the provider syncs on mount so the menu matches the webview - Info.plist: CFBundleLocalizations (en/zh-Hans/ja) + AllowMixedLocalizations so macOS auto-localizes standard menu items (Copy/Paste/About/Quit) and native dialogs - locales: add the menu.* keys, three files kept structurally identical Verified: cargo check passes; frontend tsc clean; web-side syncNativeLocale is a no-op. Native menu runtime behavior needs a real desktop build to verify (the desktop shell cannot launch in this environment).
Remove the in-app language switch UI and localStorage persistence; the language now follows the system / browser locale entirely. - Delete common/components/language-switcher.tsx and common/i18n/use-locale.ts - Remove the switcher from the landing header - config.resolveInitialLocale: navigator-only detection (drop the localStorage branch); remove switcher-only exports (LOCALE_NAMES, LOCALE_STORAGE_KEY, isLocale) - provider: inline syncNativeLocale, resolve the locale on mount and sync the native menu; no runtime switching The Rust native menu already builds from sys-locale, so both sides now key off the system locale. Verified: tsc clean, no dangling references, web follows the system locale with no console errors.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary
Adds cross-platform internationalization (English / Chinese / Japanese) to DOMD. The language follows the system / browser locale — there is no in-app switcher. English is the default fallback.
Design: the Web build and the Tauri webview share one
react-i18nextruntime setup (no[lang]routing — static export forbids Proxy/redirects/cookies). The native Rust menu reuses the samelocales/*.jsonviainclude_str!, so React and Rust share one dictionary (one source, two consumers).Commits
common/i18n/(i18next singleton,I18nProviderwith switch-after-mount to avoid hydration mismatch, navigator-based detection,locales/{en,zh,ja}.json); wired ~60 hardcoded strings across editor / updater / chat / playground / landing / save-document / errors. Shared@do-md/*packages stay i18n-free.html[lang]-keyed overrides. The code-block copy button ("Copy code"/"Copied!") is icon-only / dead CSS in the shipped@do-md/core-reactpackage, so it is deliberately left alone (overriding would show phantom text English never shows).menu_i18nmodule +build_app_menu+get_system_locale/set_localecommands (sys-localefor detection);Info.plistCFBundleLocalizationsso macOS auto-localizes standard menu items and native dialogs. The frontend invokesset_localeto keep the native menu in sync.Language resolution
zh*→ Chinese,ja*→ Japanese, anything else → English. The frontend walksnavigator.languagesand picks the first supported tag; the Rust menu normalizes the system locale the same way;fallbackLng: encovers any missing key.Verification
cargo checkpasses; frontendtscclean on changed files./,/editor,/playground.zh-CNauto-renders Chinese with no hydration / console errors.Follow-ups (not in this PR)
set_menurebuild,CFBundleLocalizations) needs a real desktop build to verify.@do-md/core-reactrelease.pickByLocale(navigator-based) — consistent with the system-locale behavior, not wired to a shared store.