text, ui: follow a language change, and resolve the language before the fonts
Review follow-ups on #312: - `crates/ui-egui/src/theme.rs`'s `japanese_font_tests` still called `install` with two arguments, so `cargo test` did not compile. Every call site now passes a language. - The call sites passed the stored `general.language` preference. With the default `system` that is `""`, which handed the CJK choice back to the environment locale — one macOS and Windows usually do not set. They now pass `crate::i18n::language(app)`, the resolved language, so Match System draws Chinese on a Chinese system. - Changing Settings ▸ General ▸ Language only reached the fonts on the first frame. `EffectcraftApp` now remembers the language its fonts were installed for and installs them again when it changes, so the switch applies without a restart. - Documented that `fonts::set_cjk_locale` is process-global: the Han preference therefore applies to composition text as well as the interface chrome (docs/preferences.md and the function's own comment). Rebased onto main after #309 landed — `header.rs` gained an `install` call site in the meantime, and the catalogs now resolve through `i18n::language`.
This commit is contained in:
@@ -274,9 +274,12 @@ static INTER_SEMIBOLD: &[u8] = include_bytes!("../../../assets/fonts/Inter-SemiB
|
||||
static JETBRAINS_MONO: &[u8] = include_bytes!("../../../assets/fonts/JetBrainsMono-Regular.ttf");
|
||||
|
||||
/// Install fonts (Inter, Inter Medium/SemiBold, JetBrains Mono) and egui visuals. `language` is the
|
||||
/// stored `general.language` value (`en`, `ja`, `zh-hans`, `zh-hant` or `system`): the CJK fallback
|
||||
/// that draws the interface's own script is registered first, so a Chinese interface is drawn by a
|
||||
/// Chinese face and a Japanese one by a Japanese face.
|
||||
/// resolved interface language from [`crate::i18n::language`] (`en`, `ja`, `zh-hans` or `zh-hant`),
|
||||
/// not the stored `general.language` preference: `system` is already resolved there, so a Chinese
|
||||
/// system draws Chinese with the default setting. The CJK fallback that draws the interface's own
|
||||
/// script is registered first, so a Chinese interface is drawn by a Chinese face and a Japanese one
|
||||
/// by a Japanese face. `install` is called again when the language changes (see the `EffectcraftApp`
|
||||
/// frame loop), so the fonts do not need a restart.
|
||||
pub fn install(ctx: &egui::Context, t: &Tokens, language: &str) {
|
||||
let mut fonts = FontDefinitions::default();
|
||||
fonts.font_data.insert("inter".into(), Arc::new(FontData::from_static(INTER_REGULAR)));
|
||||
@@ -425,7 +428,7 @@ mod japanese_font_tests {
|
||||
return;
|
||||
}
|
||||
let ctx = egui::Context::default();
|
||||
super::install(&ctx, &super::Tokens::for_kind(super::ThemeKind::Dark));
|
||||
super::install(&ctx, &super::Tokens::for_kind(super::ThemeKind::Dark), "ja");
|
||||
let mut out = ctx.run_ui(egui::RawInput::default(), |_| {});
|
||||
// No renderer here: drop the frame's texture uploads (egui asserts on unhandled ones in debug).
|
||||
out.textures_delta.clear();
|
||||
|
||||
Reference in New Issue
Block a user