Skip to content

Commit

Permalink
Add test for newlines in translations
Browse files Browse the repository at this point in the history
Fixes #12
  • Loading branch information
dima74 committed Feb 29, 2024
1 parent d413333 commit 114c411
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/crowdin_no_translations_has_newline.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use std::fs;

use fml::crowdin;
use fml::util::read_dir;

const IGNORED: &[(&str, &str, &str, &str)] = &[
// Empty translation for unknown reason, Crowdin support doesn't help
("Factorio Ultracube (grandseiken)", "de", "tips-and-tricks.ini", "cube-boiler"),
];

#[tokio::test]
async fn main() {
fml::init_with_crowdin().await;

let translations_directory = crowdin::download_all_translations().await;
let mut has_newlines = false;
// `ru/Factorio Mod Example (dima74)/locale.ini`
for (language_path, language) in read_dir(translations_directory.path()) {
for (repository_path, crowdin_name) in read_dir(&language_path) {
for (file_path, file_name) in read_dir(&repository_path) {
let content = fs::read_to_string(&file_path).unwrap();
for line in content.lines() {
if let Some(key) = line.strip_suffix('=') {
if IGNORED.contains(&(crowdin_name.as_str(), language.as_str(), file_name.as_str(), key)) {
continue;
}
has_newlines = true;
eprintln!("[{}] {}/{}: incorrect translation for key {}", crowdin_name, language, file_name, key)
}
}
}
}
}
assert!(!has_newlines);
}

0 comments on commit 114c411

Please sign in to comment.