Language selector and "requires restart" info
This commit is contained in:
@@ -7,9 +7,7 @@ use strum::{AsRefStr, EnumProperty, EnumString, VariantArray};
|
||||
use wayvr_ipc::packet_client::WvrProcessLaunchParams;
|
||||
|
||||
use crate::{
|
||||
astr_containers::{AStrMap, AStrSet},
|
||||
overlays::{BackendAttribValue, ToastDisplayMethod, ToastTopic},
|
||||
windowing::OverlayWindowState,
|
||||
astr_containers::{AStrMap, AStrSet}, locale::{self}, overlays::{BackendAttribValue, ToastDisplayMethod, ToastTopic}, windowing::OverlayWindowState
|
||||
};
|
||||
|
||||
pub type PwTokenMap = AStrMap<String>;
|
||||
@@ -140,6 +138,8 @@ const fn def_max_height() -> u16 {
|
||||
1440
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct GeneralConfig {
|
||||
#[serde(default = "def_theme_path")]
|
||||
@@ -151,6 +151,8 @@ pub struct GeneralConfig {
|
||||
pub color_faded: Option<String>,
|
||||
pub color_background: Option<String>,
|
||||
|
||||
pub language: Option<locale::Language>, // auto-detected at runtime if unset
|
||||
|
||||
#[serde(default = "def_one")]
|
||||
#[serde(alias = "ui_animation_speed", alias = "animation_speed" /* old name */)]
|
||||
pub ui_animation_speed: f32,
|
||||
|
||||
@@ -8,6 +8,7 @@ pub mod dash_interface;
|
||||
pub mod dash_interface_emulated;
|
||||
pub mod desktop_finder;
|
||||
mod handle;
|
||||
pub mod locale;
|
||||
pub mod overlays;
|
||||
pub mod timestep;
|
||||
pub mod windowing;
|
||||
|
||||
88
wlx-common/src/locale.rs
Normal file
88
wlx-common/src/locale.rs
Normal file
@@ -0,0 +1,88 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::{AsRefStr, EnumProperty, EnumString, VariantArray};
|
||||
|
||||
use crate::config::GeneralConfig;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, AsRefStr, EnumString, EnumProperty, VariantArray)]
|
||||
pub enum Language {
|
||||
#[strum(props(Text = "English"))]
|
||||
English,
|
||||
#[strum(props(Text = "Polski"))]
|
||||
Polish,
|
||||
#[strum(props(Text = "日本語"))]
|
||||
Japanese,
|
||||
#[strum(props(Text = "German"))]
|
||||
German,
|
||||
#[strum(props(Text = "Italiano"))]
|
||||
Italian,
|
||||
#[strum(props(Text = "简体中文"))]
|
||||
ChineseSimplified,
|
||||
#[strum(props(Text = "Español"))]
|
||||
Spanish,
|
||||
}
|
||||
|
||||
impl Language {
|
||||
pub const fn code(&self) -> &'static str {
|
||||
match self {
|
||||
Language::English => "en",
|
||||
Language::Polish => "pl",
|
||||
Language::Japanese => "ja",
|
||||
Language::German => "de",
|
||||
Language::Italian => "it",
|
||||
Language::ChineseSimplified => "zh_CN",
|
||||
Language::Spanish => "es",
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn get_default() -> Self {
|
||||
Self::English
|
||||
}
|
||||
|
||||
pub const fn all_codes() -> &'static [&'static str] {
|
||||
&["en", "pl", "ja", "de", "it", "zh_CN", "es"]
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WayVRLangsList {}
|
||||
|
||||
impl wgui::i18n::LangsList for WayVRLangsList {
|
||||
fn all_locale(&self) -> &'static [&'static str] {
|
||||
Language::all_codes()
|
||||
}
|
||||
|
||||
fn default_lang(&self) -> &'static str {
|
||||
Language::get_default().code()
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
const G_LANGS_LIST: WayVRLangsList = WayVRLangsList {};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct WayVRLangProvider {
|
||||
forced_lang: Option<Rc<str>>,
|
||||
}
|
||||
|
||||
impl wgui::assets::LangProvider for WayVRLangProvider {
|
||||
fn langs_list(&self) -> &dyn wgui::i18n::LangsList {
|
||||
&G_LANGS_LIST
|
||||
}
|
||||
|
||||
fn forced_lang(&self) -> Option<&str> {
|
||||
self.forced_lang.as_ref().map(|lang| lang.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
impl WayVRLangProvider {
|
||||
pub fn from_config(config: &GeneralConfig) -> Self {
|
||||
if let Some(lang) = &config.language {
|
||||
return Self {
|
||||
forced_lang: Some(lang.code().into()),
|
||||
};
|
||||
}
|
||||
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user