Use English instead of saved language if loading fails

This commit is contained in:
Rémy PHELIPOT 2020-01-22 22:15:19 +01:00
parent 8946ed8d82
commit c501b2d0bf
2 changed files with 15 additions and 4 deletions

View File

@ -48,7 +48,7 @@ impl VoxygenLocalization {
///
/// If the key is not present in the localization object
/// then the key is returned.
pub fn get<'a>(&'a self, key: &'a str) -> &'a str {
pub fn get<'a>(&'a self, key: &'a str) -> &str {
match self.string_map.get(key) {
Some(localized_text) => localized_text,
None => key,

View File

@ -34,7 +34,7 @@ use crate::{
settings::Settings,
window::Window,
};
use common::assets::load_expect;
use common::assets::{load, load_expect};
use log::{debug, error};
use std::{mem, panic, str::FromStr};
@ -139,9 +139,20 @@ fn main() {
};
// Try to load the localization and log missing entries
let localized_strings = load_expect::<VoxygenLocalization>(&i18n_asset_key(
let localized_strings = load::<VoxygenLocalization>(&i18n_asset_key(
&global_state.settings.language.selected_language,
));
))
.unwrap_or_else(|error| {
log::warn!(
"Impossible to load {} language: change to the default language (English) instead. Source error: {:?}",
&global_state.settings.language.selected_language,
error
);
global_state.settings.language.selected_language = i18n::REFERENCE_LANG.to_owned();
load_expect::<VoxygenLocalization>(&i18n_asset_key(
&global_state.settings.language.selected_language,
))
});
localized_strings.log_missing_entries();
// Set up panic handler to relay swish panic messages to the user