desktop: Use system preferred language

This commit is contained in:
Nathan Adams 2023-04-22 12:30:27 +02:00
parent 3402f3f4dc
commit 9c2e77c88f
3 changed files with 20 additions and 1 deletions

11
Cargo.lock generated
View File

@ -3690,6 +3690,7 @@ dependencies = [
"ruffle_render",
"ruffle_render_wgpu",
"ruffle_video_software",
"sys-locale",
"tracing",
"tracing-subscriber",
"tracing-tracy",
@ -4396,6 +4397,16 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "sys-locale"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea0b9eefabb91675082b41eb94c3ecd91af7656caee3fb4961a07c0ec8c7ca6f"
dependencies = [
"libc",
"windows-sys 0.45.0",
]
[[package]]
name = "system-deps"
version = "6.0.5"

View File

@ -28,6 +28,7 @@ anyhow = "1.0"
bytemuck = "1.13.1"
os_info = { version = "3", default-features = false }
unic-langid = "0.9.1"
sys-locale = "0.3.0"
# Deliberately held back to match tracy client used by profiling crate
tracing-tracy = { version = "=0.10.0", optional = true }

View File

@ -5,6 +5,7 @@ use ruffle_core::backend::ui::{
FullscreenError, LanguageIdentifier, MouseCursor, UiBackend, US_ENGLISH,
};
use std::rc::Rc;
use sys_locale::get_locale;
use tracing::error;
use winit::window::{Fullscreen, Window};
@ -12,14 +13,20 @@ pub struct DesktopUiBackend {
window: Rc<Window>,
cursor_visible: bool,
clipboard: Clipboard,
language: LanguageIdentifier,
}
impl DesktopUiBackend {
pub fn new(window: Rc<Window>) -> Result<Self, Error> {
let preferred_language = get_locale();
let language = preferred_language
.and_then(|l| l.parse().ok())
.unwrap_or_else(|| US_ENGLISH.clone());
Ok(Self {
window,
cursor_visible: true,
clipboard: Clipboard::new().context("Couldn't get platform clipboard")?,
language,
})
}
}
@ -101,6 +108,6 @@ impl UiBackend for DesktopUiBackend {
fn open_virtual_keyboard(&self) {}
fn language(&self) -> &LanguageIdentifier {
&US_ENGLISH
&self.language
}
}