mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'juliancoffee/stricter-localization-tests' into 'master'
Improve i18n analytic tools See merge request veloren/veloren!3566
This commit is contained in:
commit
cfec8b5e9d
@ -2,7 +2,4 @@
|
||||
VELOREN_ASSETS="$(pwd)/assets"
|
||||
export VELOREN_ASSETS
|
||||
|
||||
time cargo test --package veloren-voxygen-i18n \
|
||||
--lib test_all_localizations \
|
||||
--features="stat" \
|
||||
-- --nocapture --ignored
|
||||
time cargo run --bin i18n-csv --features="stat"
|
||||
|
@ -1,4 +1,8 @@
|
||||
#!/bin/bash
|
||||
export VELOREN_ASSETS="$(pwd)/assets"
|
||||
time cargo test --package veloren-common-assets asset_tweak::tests --features asset_tweak --lib &&
|
||||
VELOREN_ASSETS="$(pwd)/assets"
|
||||
export VELOREN_ASSETS
|
||||
|
||||
time cargo test \
|
||||
--package veloren-common-assets asset_tweak::tests \
|
||||
--features asset_tweak --lib &&
|
||||
time cargo test
|
||||
|
@ -27,6 +27,10 @@ fluent-syntax = { git = "https://github.com/juliancoffee/fluent-rs.git", branch
|
||||
name = "i18n-check"
|
||||
required-features = ["bin"]
|
||||
|
||||
[[bin]]
|
||||
name = "i18n-csv"
|
||||
required-features = ["stat"]
|
||||
|
||||
[features]
|
||||
bin = ["clap"]
|
||||
stat = []
|
||||
|
@ -30,13 +30,14 @@ fn keys_from_file(filepath: &Path) -> Vec<MsgId> {
|
||||
ResourceErr::parsing_error(errs, file.clone(), &content)
|
||||
)
|
||||
});
|
||||
|
||||
let mut keys = Vec::new();
|
||||
for entry in ast.body {
|
||||
match entry {
|
||||
Entry::Message(m) => {
|
||||
keys.push(MsgId {
|
||||
key: m.id.name.to_owned(),
|
||||
file: Some(file.clone()),
|
||||
file: file.clone(),
|
||||
});
|
||||
},
|
||||
Entry::Term(_)
|
||||
@ -79,7 +80,7 @@ fn keys(from: &Path, tree: &Walk) -> Vec<MsgId> {
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MsgId {
|
||||
pub key: String,
|
||||
pub file: Option<String>,
|
||||
pub file: String,
|
||||
}
|
||||
|
||||
// TODO:
|
||||
@ -121,10 +122,7 @@ impl ReferenceLanguage {
|
||||
if let Some(key) = keys.iter().find(|MsgId { key, .. }| &ref_key.key == key) {
|
||||
stats.up_to_date.push(key.clone());
|
||||
} else {
|
||||
stats.not_found.push(MsgId {
|
||||
key: ref_key.key.clone(),
|
||||
file: None,
|
||||
});
|
||||
stats.not_found.push(ref_key.clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
57
voxygen/i18n/src/bin/i18n-csv.rs
Normal file
57
voxygen/i18n/src/bin/i18n-csv.rs
Normal file
@ -0,0 +1,57 @@
|
||||
use common_assets::find_root;
|
||||
use std::{fs, io::Write, path::Path};
|
||||
use veloren_voxygen_i18n::{
|
||||
analysis::{Language, ReferenceLanguage},
|
||||
list_localizations, REFERENCE_LANG,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
let root = find_root().unwrap();
|
||||
let output = root.join("translation_analysis.csv");
|
||||
let mut f = fs::File::create(output).expect("couldn't write csv file");
|
||||
|
||||
writeln!(
|
||||
f,
|
||||
"country_code,file_name,translation_key,status,git_commit"
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let i18n_directory = root.join("assets/voxygen/i18n");
|
||||
let reference = ReferenceLanguage::at(&i18n_directory.join(REFERENCE_LANG));
|
||||
|
||||
let list = list_localizations();
|
||||
let file = |filename| {
|
||||
let file = Path::new(&filename)
|
||||
.file_name()
|
||||
.and_then(|s| s.to_str())
|
||||
.unwrap_or("<err>");
|
||||
|
||||
format!("{file}")
|
||||
};
|
||||
for meta in list {
|
||||
let code = meta.language_identifier;
|
||||
let lang = Language {
|
||||
code: code.clone(),
|
||||
path: i18n_directory.join(code.clone()),
|
||||
};
|
||||
let stats = reference.compare_with(&lang);
|
||||
for key in stats.up_to_date {
|
||||
let code = &code;
|
||||
let filename = file(key.file);
|
||||
let key = &key.key;
|
||||
writeln!(f, "{code},{filename},{key},UpToDate,None").unwrap();
|
||||
}
|
||||
for key in stats.not_found {
|
||||
let code = &code;
|
||||
let filename = file(key.file);
|
||||
let key = &key.key;
|
||||
writeln!(f, "{code},{filename},{key},NotFound,None").unwrap();
|
||||
}
|
||||
for key in stats.unused {
|
||||
let code = &code;
|
||||
let filename = file(key.file);
|
||||
let key = &key.key;
|
||||
writeln!(f, "{code},{filename},{key},Unused,None").unwrap();
|
||||
}
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@ mod raw;
|
||||
|
||||
use error::ResourceErr;
|
||||
|
||||
#[cfg(any(feature = "bin", feature = "stat"))]
|
||||
#[cfg(any(feature = "bin", feature = "stat", test))]
|
||||
pub mod analysis;
|
||||
|
||||
use fluent_bundle::{bundle::FluentBundle, FluentResource};
|
||||
@ -163,10 +163,6 @@ impl assets::Compound for Language {
|
||||
|
||||
// Here go dragons
|
||||
for id in cache.load_dir::<raw::Resource>(path, true)?.ids() {
|
||||
if id.ends_with("_manifest") {
|
||||
continue;
|
||||
}
|
||||
|
||||
match cache.load(id) {
|
||||
Ok(handle) => {
|
||||
let source: &raw::Resource = &*handle.read();
|
||||
@ -518,63 +514,25 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
#[cfg(feature = "stat")]
|
||||
// Generate translation stats
|
||||
fn test_all_localizations() {
|
||||
fn test_strict_all_localizations() {
|
||||
use analysis::{Language, ReferenceLanguage};
|
||||
use assets::find_root;
|
||||
use std::{fs, io::Write, path::Path};
|
||||
|
||||
let root = find_root().unwrap();
|
||||
let output = root.join("translation_analysis.csv");
|
||||
let mut f = fs::File::create(output).expect("couldn't write csv file");
|
||||
|
||||
writeln!(
|
||||
f,
|
||||
"country_code,file_name,translation_key,status,git_commit"
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let i18n_directory = root.join("assets/voxygen/i18n");
|
||||
let reference = ReferenceLanguage::at(&i18n_directory.join(REFERENCE_LANG));
|
||||
|
||||
let list = list_localizations();
|
||||
let file = |filename: Option<String>| {
|
||||
let file = filename
|
||||
.as_ref()
|
||||
.map(|s| Path::new(s))
|
||||
.and_then(|p| p.file_name())
|
||||
.and_then(|s| s.to_str())
|
||||
.unwrap_or("None");
|
||||
|
||||
format!("{file}")
|
||||
};
|
||||
for meta in list {
|
||||
let code = meta.language_identifier;
|
||||
let lang = Language {
|
||||
code: code.clone(),
|
||||
path: i18n_directory.join(code.clone()),
|
||||
};
|
||||
let stats = reference.compare_with(&lang);
|
||||
for key in stats.up_to_date {
|
||||
let code = &code;
|
||||
let filename = &file(key.file);
|
||||
let key = &key.key;
|
||||
writeln!(f, "{code},{filename},{key},UpToDate,None").unwrap();
|
||||
}
|
||||
for key in stats.not_found {
|
||||
let code = &code;
|
||||
let filename = &file(key.file);
|
||||
let key = &key.key;
|
||||
writeln!(f, "{code},{filename},{key},NotFound,None").unwrap();
|
||||
}
|
||||
for key in stats.unused {
|
||||
let code = &code;
|
||||
let filename = &file(key.file);
|
||||
let key = &key.key;
|
||||
writeln!(f, "{code},{filename},{key},Unused,None").unwrap();
|
||||
}
|
||||
// TODO: somewhere here should go check that all needed
|
||||
// versions are given
|
||||
reference.compare_with(&lang);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user