diff --git a/voxygen/src/i18n.rs b/voxygen/src/i18n.rs index 62413bd316..1a046b4035 100644 --- a/voxygen/src/i18n.rs +++ b/voxygen/src/i18n.rs @@ -247,24 +247,38 @@ impl assets::Compound for Localization { } } -/// Load all the available languages located in the voxygen asset directory -pub fn list_localizations() -> Vec { - let mut languages = vec![]; - // List language directories - let i18n_root = assets::path_of("voxygen.i18n", ""); - for i18n_directory in std::fs::read_dir(&i18n_root).unwrap() { - if let Ok(i18n_entry) = i18n_directory { - if let Some(i18n_key) = i18n_entry.file_name().to_str() { - // load the root file of all the subdirectories - if let Ok(localization) = RawLocalization::load( - &("voxygen.i18n.".to_string() + i18n_key + "." + LANG_MANIFEST_FILE), - ) { - languages.push(localization.read().metadata.clone()); +#[derive(Clone, Debug)] +struct LocalizationList(Vec); + +impl assets::Compound for LocalizationList { + fn load( + cache: &assets::AssetCache, + specifier: &str, + ) -> Result { + // List language directories + let mut languages = vec![]; + + let i18n_root = assets::path_of(specifier, ""); + for i18n_directory in std::fs::read_dir(&i18n_root)? { + if let Ok(i18n_entry) = i18n_directory { + if let Some(i18n_key) = i18n_entry.file_name().to_str() { + // load the root file of all the subdirectories + if let Ok(localization) = cache.load::( + &(specifier.to_string() + "." + i18n_key + "." + LANG_MANIFEST_FILE), + ) { + languages.push(localization.read().metadata.clone()); + } } } } + + Ok(LocalizationList(languages)) } - languages +} + +/// Load all the available languages located in the voxygen asset directory +pub fn list_localizations() -> Vec { + LocalizationList::load_expect_cloned("voxygen.i18n").0 } /// Return the asset associated with the language_id