wgui: basic i18n support, refactoring: use LayoutState, translation framework (LLM-based generator)

This commit is contained in:
Aleksander
2025-08-02 23:31:23 +02:00
parent 4e46c45bcf
commit eaa81450b5
45 changed files with 916 additions and 223 deletions

34
wgui/src/globals.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::{
cell::{RefCell, RefMut},
rc::Rc,
};
use crate::{assets::AssetProvider, i18n::I18n};
pub struct Globals {
pub assets: Box<dyn AssetProvider>,
pub i18n: I18n,
}
#[derive(Clone)]
pub struct WguiGlobals(Rc<RefCell<Globals>>);
impl WguiGlobals {
pub fn new(mut assets: Box<dyn AssetProvider>) -> anyhow::Result<Self> {
let i18n = I18n::new(&mut assets)?;
Ok(Self(Rc::new(RefCell::new(Globals { assets, i18n }))))
}
pub fn get(&self) -> RefMut<Globals> {
self.0.borrow_mut()
}
pub fn i18n(&self) -> RefMut<I18n> {
RefMut::map(self.0.borrow_mut(), |x| &mut x.i18n)
}
pub fn assets(&self) -> RefMut<Box<dyn AssetProvider>> {
RefMut::map(self.0.borrow_mut(), |x| &mut x.assets)
}
}