fallback fonts

This commit is contained in:
galister
2026-01-07 03:41:07 +09:00
parent 954e1c3157
commit 578165ee5b
4 changed files with 16 additions and 8 deletions

View File

@@ -1,7 +1,7 @@
{ {
"HOME_SCREEN": "ホーム", "HOME_SCREEN": "ホーム",
"MONADO_RUNTIME": "「Monado」ランタイム", "MONADO_RUNTIME": "「Monado」ランタイム",
"APPLICATIONS": "アプリケーション", "APPLICATIONS": "アプリ",
"GAMES": "ゲーム", "GAMES": "ゲーム",
"SETTINGS": "設定", "SETTINGS": "設定",
"PROCESSES": "プロセス", "PROCESSES": "プロセス",

View File

@@ -1,3 +1,4 @@
use cosmic_text::PlatformFallback;
use parking_lot::Mutex; use parking_lot::Mutex;
#[derive(Default)] #[derive(Default)]
@@ -13,12 +14,15 @@ pub struct WguiFontSystem {
} }
impl 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 mut db = cosmic_text::fontdb::Database::new();
let system = if config.binaries.is_empty() { let system = if config.binaries.is_empty() {
cosmic_text::FontSystem::new() cosmic_text::FontSystem::new()
} else { } else {
// needed for fallback
db.load_system_fonts();
for binary in &config.binaries { for binary in &config.binaries {
// binary data is copied and preserved here // binary data is copied and preserved here
db.load_font_data(binary.to_vec()); db.load_font_data(binary.to_vec());
@@ -33,9 +37,7 @@ impl WguiFontSystem {
} }
// we don't require anything special, at least for now // we don't require anything special, at least for now
let locale = String::from("C"); cosmic_text::FontSystem::new_with_locale_and_db_and_fallback(lang.to_string(), db, PlatformFallback)
cosmic_text::FontSystem::new_with_locale_and_db(locale, db)
}; };
Self { Self {

View File

@@ -72,10 +72,10 @@ impl WguiGlobals {
Ok(Self(Rc::new(RefCell::new(Globals { Ok(Self(Rc::new(RefCell::new(Globals {
assets_internal, assets_internal,
assets_builtin, assets_builtin,
i18n_builtin,
defaults, defaults,
asset_folder, 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(), custom_glyph_cache: CustomGlyphCache::new(),
})))) }))))
} }

View File

@@ -58,6 +58,7 @@ impl Translation {
} }
pub struct I18n { pub struct I18n {
lang: String,
json_root_translated: serde_json::Value, // any language json_root_translated: serde_json::Value, // any language
json_root_fallback: serde_json::Value, // english json_root_fallback: serde_json::Value, // english
} }
@@ -123,11 +124,16 @@ impl I18n {
.context("Translation file not valid JSON")?; .context("Translation file not valid JSON")?;
Ok(Self { Ok(Self {
lang,
json_root_translated, json_root_translated,
json_root_fallback, json_root_fallback,
}) })
} }
pub fn get_lang(&self) -> &str {
&self.lang
}
pub fn translate(&mut self, translation_key_full: &str) -> Rc<str> { pub fn translate(&mut self, translation_key_full: &str) -> Rc<str> {
let mut sections = translation_key_full.split(';'); let mut sections = translation_key_full.split(';');
let translation_key = sections.next().map_or(translation_key_full, |a| a); let translation_key = sections.next().map_or(translation_key_full, |a| a);