Skip to main content

fcl_with_mt_metadata/
fcl_with_mt_metadata.rs

1use ferrocat::{
2    CatalogMode, CatalogUpdateInput, EffectiveTranslationRef, SourceExtractedMessage,
3    UpdateCatalogOptions, machine_translation_hash, update_catalog,
4};
5
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let hash = machine_translation_hash(EffectiveTranslationRef::Singular("Hallo"));
8    let existing = format!(
9        "%FCL1\tsource=en\tlocale=de\nHello\t\tHallo\tlock={hash}\tai=example/mt:0.92\n",
10        hash = hash
11    );
12
13    let input = CatalogUpdateInput::SourceFirst(vec![SourceExtractedMessage {
14        msgid: "Hello".to_owned(),
15        ..SourceExtractedMessage::default()
16    }]);
17    let result = update_catalog(
18        UpdateCatalogOptions::new("en", input)
19            .with_locale("de")
20            .with_mode(CatalogMode::IcuFcl)
21            .with_existing(&existing),
22    )?;
23
24    assert!(result.content.starts_with("%FCL1"));
25    assert!(result.content.contains("ai=example/mt:0.92"));
26    assert!(result.content.contains(&hash));
27
28    println!("{}", result.content);
29    Ok(())
30}