Skip to content

Commit 957d596

Browse files
committed
Add translate coverage for strings and Android XML
1 parent ee3579b commit 957d596

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

langcodec-cli/src/translate.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,6 +1869,68 @@ cp "{payload_path}" "$pull_path/$namespace/Localizable.xcstrings"
18691869
assert!(written.contains("\"bye\" = \"Au revoir\";"));
18701870
}
18711871

1872+
#[test]
1873+
fn translates_strings_source_into_android_target_file() {
1874+
let temp_dir = TempDir::new().unwrap();
1875+
let source = temp_dir.path().join("en.strings");
1876+
let target_dir = temp_dir.path().join("values-fr");
1877+
let target = target_dir.join("strings.xml");
1878+
fs::create_dir_all(&target_dir).unwrap();
1879+
fs::write(
1880+
&source,
1881+
"\"welcome\" = \"Welcome\";\n\"bye\" = \"Goodbye\";\n",
1882+
)
1883+
.unwrap();
1884+
1885+
let prepared = prepare_translation(&base_options(&source, Some(&target))).unwrap();
1886+
let outcome = run_prepared_translation(
1887+
prepared,
1888+
Some(Arc::new(MockBackend::new(vec![
1889+
(("welcome", "fr"), Ok("Bienvenue".to_string())),
1890+
(("bye", "fr"), Ok("Au revoir".to_string())),
1891+
]))),
1892+
)
1893+
.unwrap();
1894+
1895+
assert_eq!(outcome.translated, 2);
1896+
let written = fs::read_to_string(&target).unwrap();
1897+
assert!(written.contains("<string name=\"welcome\">Bienvenue</string>"));
1898+
assert!(written.contains("<string name=\"bye\">Au revoir</string>"));
1899+
}
1900+
1901+
#[test]
1902+
fn translates_android_source_into_strings_target_file() {
1903+
let temp_dir = TempDir::new().unwrap();
1904+
let source_dir = temp_dir.path().join("values");
1905+
let source = source_dir.join("strings.xml");
1906+
let target = temp_dir.path().join("fr.strings");
1907+
fs::create_dir_all(&source_dir).unwrap();
1908+
fs::write(
1909+
&source,
1910+
r#"<resources>
1911+
<string name="welcome">Welcome</string>
1912+
<string name="bye">Goodbye</string>
1913+
</resources>
1914+
"#,
1915+
)
1916+
.unwrap();
1917+
1918+
let prepared = prepare_translation(&base_options(&source, Some(&target))).unwrap();
1919+
let outcome = run_prepared_translation(
1920+
prepared,
1921+
Some(Arc::new(MockBackend::new(vec![
1922+
(("welcome", "fr"), Ok("Bienvenue".to_string())),
1923+
(("bye", "fr"), Ok("Au revoir".to_string())),
1924+
]))),
1925+
)
1926+
.unwrap();
1927+
1928+
assert_eq!(outcome.translated, 2);
1929+
let written = fs::read_to_string(&target).unwrap();
1930+
assert!(written.contains("\"welcome\" = \"Bienvenue\";"));
1931+
assert!(written.contains("\"bye\" = \"Au revoir\";"));
1932+
}
1933+
18721934
#[test]
18731935
fn dry_run_does_not_write_target() {
18741936
let temp_dir = TempDir::new().unwrap();

0 commit comments

Comments
 (0)