From ed840e916f75c01419354f52e70121598003290e Mon Sep 17 00:00:00 2001 From: George Atkinson Date: Wed, 20 Jul 2022 01:06:51 +0100 Subject: [PATCH] Remove unwrap on system language parsing --- core/src/environment.rs | 2 +- core/src/resource.rs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/environment.rs b/core/src/environment.rs index ae67de069..743dcea7e 100644 --- a/core/src/environment.rs +++ b/core/src/environment.rs @@ -18,7 +18,7 @@ impl Default for Environment { impl Environment { pub fn new() -> Self { - let locale = sys_locale::get_locale().map(|l| l.parse().unwrap()).unwrap_or_default(); + let locale = sys_locale::get_locale().map(|l| l.parse().ok()).flatten().unwrap_or_default(); Self { locale, include_default_theme: true } } diff --git a/core/src/resource.rs b/core/src/resource.rs index 9a9c506de..245484276 100644 --- a/core/src/resource.rs +++ b/core/src/resource.rs @@ -76,7 +76,7 @@ pub struct ResourceManager { impl ResourceManager { pub fn new() -> Self { - let locale = sys_locale::get_locale().map(|l| l.parse().unwrap()).unwrap_or_default(); + let locale = sys_locale::get_locale().map(|l| l.parse().ok()).flatten().unwrap_or_default(); ResourceManager { stylesheets: Vec::new(), @@ -100,7 +100,8 @@ impl ResourceManager { .filter(|&x| x != &LanguageIdentifier::default()) .collect::>(); let locale = sys_locale::get_locale() - .map(|l| l.parse().unwrap()) + .map(|l| l.parse().ok()) + .flatten() .unwrap_or_else(|| available.first().copied().cloned().unwrap_or_default()); let default = LanguageIdentifier::default(); let default_ref = &default; // ???