ndjson_with_mt_metadata/
ndjson_with_mt_metadata.rs1use 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 concat!(
10 "---\n",
11 "format: ferrocat.ndjson.v1\n",
12 "locale: de\n",
13 "source_locale: en\n",
14 "---\n",
15 "{{\"id\":\"Hello\",\"str\":\"Hallo\",\"mt\":{{\"model\":\"example/mt\",\"confidence\":92,\"hash\":\"{hash}\"}}}}\n"
16 ),
17 hash = hash
18 );
19
20 let result = update_catalog(UpdateCatalogOptions {
21 locale: Some("de"),
22 mode: CatalogMode::IcuNdjson,
23 existing: Some(&existing),
24 input: CatalogUpdateInput::SourceFirst(vec![SourceExtractedMessage {
25 msgid: "Hello".to_owned(),
26 ..SourceExtractedMessage::default()
27 }]),
28 ..UpdateCatalogOptions::new("en", CatalogUpdateInput::default())
29 })?;
30
31 assert!(result.content.contains("format: ferrocat.ndjson.v1"));
32 assert!(result.content.contains("\"model\":\"example/mt\""));
33 assert!(result.content.contains(&hash));
34
35 println!("{}", result.content);
36 Ok(())
37}