mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
verify every localization file instead of just the manifest
This commit is contained in:
parent
b1f2a4eff5
commit
f8cb45f2f0
@ -216,6 +216,7 @@ impl assets::Compound for Localization {
|
||||
.vector_map
|
||||
.extend(localization_asset.read().vector_map.clone());
|
||||
}
|
||||
|
||||
// Use the localization's subdirectory list to load fragments from there
|
||||
for sub_directory in localization.sub_directories.iter() {
|
||||
for localization_asset in cache
|
||||
@ -451,6 +452,35 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
fn verify_localization_directory(directory_path: &Path) {
|
||||
let root_dir = std::env::current_dir()
|
||||
.map(|p| p.parent().expect("").to_owned())
|
||||
.unwrap();
|
||||
// Walk through each file in the directory
|
||||
for i18n_file in root_dir.join(&directory_path).read_dir().unwrap() {
|
||||
if let Ok(i18n_file) = i18n_file {
|
||||
if let Ok(file_type) = i18n_file.file_type() {
|
||||
// Skip folders and the manifest file (which does not contain the same struct we want to load)
|
||||
if file_type.is_file() && i18n_file.file_name().to_string_lossy() != (LANG_MANIFEST_FILE.to_string() + ".ron") {
|
||||
let full_path = i18n_file.path();
|
||||
println!("-> {:?}", full_path.strip_prefix(&root_dir).unwrap());
|
||||
let f = fs::File::open(&full_path).expect("Failed opening file");
|
||||
let _: LocalizationFragment = match from_reader(f) {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
panic!(
|
||||
"Could not parse {} RON file, error: {}",
|
||||
full_path.to_string_lossy(),
|
||||
e
|
||||
);
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test to verify all languages that they are VALID and loadable, without
|
||||
// need of git just on the local assets folder
|
||||
#[test]
|
||||
@ -480,19 +510,28 @@ mod tests {
|
||||
"have less than 5 translation folders, arbitrary minimum check failed. Maybe the i18n \
|
||||
folder is empty?"
|
||||
);
|
||||
for path in i18n_directories {
|
||||
let path = path.join(LANG_MANIFEST_FILE.to_string() + ".ron");
|
||||
let f = fs::File::open(&path).expect("Failed opening file");
|
||||
let _: RawLocalization = match from_reader(f) {
|
||||
for i18n_directory in i18n_directories {
|
||||
// Attempt to load the manifest file
|
||||
let manifest_path = i18n_directory.join(LANG_MANIFEST_FILE.to_string() + ".ron");
|
||||
println!("verifying {:?}", manifest_path.strip_prefix(&root_dir).unwrap());
|
||||
let f = fs::File::open(&manifest_path).expect("Failed opening file");
|
||||
let raw_localization: RawLocalization = match from_reader(f) {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
panic!(
|
||||
"Could not parse {} RON file, error: {}",
|
||||
path.to_string_lossy(),
|
||||
i18n_directory.to_string_lossy(),
|
||||
e
|
||||
);
|
||||
},
|
||||
};
|
||||
// Walk through each files and try to load them
|
||||
verify_localization_directory(&i18n_directory);
|
||||
// Walk through each subdirectories and try to load files in them
|
||||
for sub_directory in raw_localization.sub_directories.iter() {
|
||||
let subdir_path = &i18n_directory.join(sub_directory);
|
||||
verify_localization_directory(&subdir_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user