From 578165ee5bd3b2b56c42e6c7e0326c4ef31ae7ec Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Wed, 7 Jan 2026 03:41:07 +0900 Subject: [PATCH] fallback fonts --- dash-frontend/assets/lang/ja.json | 4 ++-- wgui/src/font_config.rs | 10 ++++++---- wgui/src/globals.rs | 4 ++-- wgui/src/i18n.rs | 6 ++++++ 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/dash-frontend/assets/lang/ja.json b/dash-frontend/assets/lang/ja.json index 9c7d7c8..2dcf3b0 100644 --- a/dash-frontend/assets/lang/ja.json +++ b/dash-frontend/assets/lang/ja.json @@ -1,7 +1,7 @@ { "HOME_SCREEN": "ホーム", "MONADO_RUNTIME": "「Monado」ランタイム", - "APPLICATIONS": "アプリケーション", + "APPLICATIONS": "アプリ", "GAMES": "ゲーム", "SETTINGS": "設定", "PROCESSES": "プロセス", @@ -103,4 +103,4 @@ }, "TERMINATE_PROCESS": "プロセスを終了する", "GAME_LAUNCHED": "ゲームが起動しました" -} \ No newline at end of file +} diff --git a/wgui/src/font_config.rs b/wgui/src/font_config.rs index d6278e7..dc59fc3 100644 --- a/wgui/src/font_config.rs +++ b/wgui/src/font_config.rs @@ -1,3 +1,4 @@ +use cosmic_text::PlatformFallback; use parking_lot::Mutex; #[derive(Default)] @@ -13,12 +14,15 @@ pub struct WguiFontSystem { } impl WguiFontSystem { - pub fn new(config: &WguiFontConfig) -> Self { + pub fn new(config: &WguiFontConfig, lang: &str) -> Self { let mut db = cosmic_text::fontdb::Database::new(); let system = if config.binaries.is_empty() { cosmic_text::FontSystem::new() } else { + // needed for fallback + db.load_system_fonts(); + for binary in &config.binaries { // binary data is copied and preserved here db.load_font_data(binary.to_vec()); @@ -33,9 +37,7 @@ impl WguiFontSystem { } // we don't require anything special, at least for now - let locale = String::from("C"); - - cosmic_text::FontSystem::new_with_locale_and_db(locale, db) + cosmic_text::FontSystem::new_with_locale_and_db_and_fallback(lang.to_string(), db, PlatformFallback) }; Self { diff --git a/wgui/src/globals.rs b/wgui/src/globals.rs index e9573dd..bda6ed4 100644 --- a/wgui/src/globals.rs +++ b/wgui/src/globals.rs @@ -72,10 +72,10 @@ impl WguiGlobals { Ok(Self(Rc::new(RefCell::new(Globals { assets_internal, assets_builtin, - i18n_builtin, defaults, asset_folder, - font_system: WguiFontSystem::new(font_config), + font_system: WguiFontSystem::new(font_config, i18n_builtin.get_lang()), + i18n_builtin, custom_glyph_cache: CustomGlyphCache::new(), })))) } diff --git a/wgui/src/i18n.rs b/wgui/src/i18n.rs index baa2440..bdc4e4a 100644 --- a/wgui/src/i18n.rs +++ b/wgui/src/i18n.rs @@ -58,6 +58,7 @@ impl Translation { } pub struct I18n { + lang: String, json_root_translated: serde_json::Value, // any language json_root_fallback: serde_json::Value, // english } @@ -123,11 +124,16 @@ impl I18n { .context("Translation file not valid JSON")?; Ok(Self { + lang, json_root_translated, json_root_fallback, }) } + pub fn get_lang(&self) -> &str { + &self.lang + } + pub fn translate(&mut self, translation_key_full: &str) -> Rc { let mut sections = translation_key_full.split(';'); let translation_key = sections.next().map_or(translation_key_full, |a| a);