Make i18n csv own binary

* Put file that needs care back into csv
This commit is contained in:
juliancoffee 2022-08-25 14:13:28 +03:00
parent 9a0ac8dcce
commit f2eb1fe7c8
5 changed files with 69 additions and 50 deletions

View File

@ -2,7 +2,4 @@
VELOREN_ASSETS="$(pwd)/assets" VELOREN_ASSETS="$(pwd)/assets"
export VELOREN_ASSETS export VELOREN_ASSETS
time cargo test --package veloren-voxygen-i18n \ time cargo run --bin i18n-csv --features="stat"
--lib test_all_localizations \
--features="stat" \
-- --nocapture --ignored

View File

@ -27,6 +27,10 @@ fluent-syntax = { git = "https://github.com/juliancoffee/fluent-rs.git", branch
name = "i18n-check" name = "i18n-check"
required-features = ["bin"] required-features = ["bin"]
[[bin]]
name = "i18n-csv"
required-features = ["stat"]
[features] [features]
bin = ["clap"] bin = ["clap"]
stat = [] stat = []

View File

@ -37,7 +37,7 @@ fn keys_from_file(filepath: &Path) -> Vec<MsgId> {
Entry::Message(m) => { Entry::Message(m) => {
keys.push(MsgId { keys.push(MsgId {
key: m.id.name.to_owned(), key: m.id.name.to_owned(),
file: Some(file.clone()), file: file.clone(),
}); });
}, },
Entry::Term(_) Entry::Term(_)
@ -80,7 +80,7 @@ fn keys(from: &Path, tree: &Walk) -> Vec<MsgId> {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct MsgId { pub struct MsgId {
pub key: String, pub key: String,
pub file: Option<String>, pub file: String,
} }
// TODO: // TODO:
@ -122,10 +122,7 @@ impl ReferenceLanguage {
if let Some(key) = keys.iter().find(|MsgId { key, .. }| &ref_key.key == key) { if let Some(key) = keys.iter().find(|MsgId { key, .. }| &ref_key.key == key) {
stats.up_to_date.push(key.clone()); stats.up_to_date.push(key.clone());
} else { } else {
stats.not_found.push(MsgId { stats.not_found.push(ref_key.clone());
key: ref_key.key.clone(),
file: None,
});
} }
} }

View 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();
}
}
}

View File

@ -515,61 +515,25 @@ mod tests {
#[test] #[test]
#[cfg(feature = "stat")] #[cfg(feature = "stat")]
// Generate translation stats fn test_strict_all_localizations() {
fn test_all_localizations() {
use analysis::{Language, ReferenceLanguage}; use analysis::{Language, ReferenceLanguage};
use assets::find_root; use assets::find_root;
use std::{fs, io::Write, path::Path};
let root = find_root().unwrap(); 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 i18n_directory = root.join("assets/voxygen/i18n");
let reference = ReferenceLanguage::at(&i18n_directory.join(REFERENCE_LANG)); let reference = ReferenceLanguage::at(&i18n_directory.join(REFERENCE_LANG));
let list = list_localizations(); 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 { for meta in list {
let code = meta.language_identifier; let code = meta.language_identifier;
let lang = Language { let lang = Language {
code: code.clone(), code: code.clone(),
path: i18n_directory.join(code.clone()), path: i18n_directory.join(code.clone()),
}; };
let stats = reference.compare_with(&lang); // TODO: somewhere here should go check that all needed
for key in stats.up_to_date { // versions are given
let code = &code; reference.compare_with(&lang);
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();
}
} }
} }
} }