-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for newlines in translations
Fixes #12
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |