#[non_exhaustive]pub struct UpdateCatalogOptions<'a> {
pub locale: Option<&'a str>,
pub source_locale: &'a str,
pub input: CatalogUpdateInput,
pub existing: Option<&'a str>,
pub mode: CatalogMode,
pub obsolete_strategy: ObsoleteStrategy,
pub overwrite_source_translations: bool,
pub now: Option<&'a str>,
pub render: RenderOptions<'a>,
}catalog only.Expand description
Options for in-memory catalog updates.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.locale: Option<&'a str>Locale of the catalog being updated. When None, Ferrocat infers it from the existing file.
source_locale: &'a strSource locale used for source-side semantics and fallback handling.
input: CatalogUpdateInputExtracted messages to merge into the catalog.
existing: Option<&'a str>Existing catalog content, when updating an in-memory catalog.
mode: CatalogModeHigh-level catalog mode used when parsing, merging, and rendering the catalog.
obsolete_strategy: ObsoleteStrategyStrategy for messages absent from the extracted input.
overwrite_source_translations: boolWhether source-locale translations should be refreshed from the extracted source strings.
now: Option<&'a str>Optional host-provided clock as an ISO-8601 date. When set, entries newly
transitioning to obsolete are stamped with this since date (write-once).
Ferrocat never reads a clock itself, so updates stay deterministic given
their inputs. See ADR 0025.
render: RenderOptions<'a>Shared serialization options for the rendered catalog.
Implementations§
Source§impl<'a> UpdateCatalogOptions<'a>
impl<'a> UpdateCatalogOptions<'a>
Sourcepub fn new(
source_locale: &'a str,
input: impl Into<CatalogUpdateInput>,
) -> UpdateCatalogOptions<'a>
pub fn new( source_locale: &'a str, input: impl Into<CatalogUpdateInput>, ) -> UpdateCatalogOptions<'a>
Creates in-memory update options with required fields set.
Optional fields default to an inferred locale, ICU-native PO mode,
marking missing messages obsolete, preserving source-locale translations,
no host clock, and RenderOptions::default.
Examples found in repository?
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}Sourcepub fn with_locale(self, locale: &'a str) -> UpdateCatalogOptions<'a>
pub fn with_locale(self, locale: &'a str) -> UpdateCatalogOptions<'a>
Returns options that use the given catalog locale.
Examples found in repository?
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}Sourcepub fn with_existing(self, existing: &'a str) -> UpdateCatalogOptions<'a>
pub fn with_existing(self, existing: &'a str) -> UpdateCatalogOptions<'a>
Returns options that update the given existing catalog content.
Examples found in repository?
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}Sourcepub fn with_mode(self, mode: CatalogMode) -> UpdateCatalogOptions<'a>
pub fn with_mode(self, mode: CatalogMode) -> UpdateCatalogOptions<'a>
Returns options that parse, merge, and render with the given catalog mode.
Examples found in repository?
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}Sourcepub fn with_render(self, render: RenderOptions<'a>) -> UpdateCatalogOptions<'a>
pub fn with_render(self, render: RenderOptions<'a>) -> UpdateCatalogOptions<'a>
Returns options that render the updated catalog with the given options.
Sourcepub fn with_obsolete_strategy(
self,
obsolete_strategy: ObsoleteStrategy,
) -> UpdateCatalogOptions<'a>
pub fn with_obsolete_strategy( self, obsolete_strategy: ObsoleteStrategy, ) -> UpdateCatalogOptions<'a>
Returns options that handle missing extracted messages with the given strategy.
Sourcepub fn with_overwrite_source_translations(
self,
overwrite_source_translations: bool,
) -> UpdateCatalogOptions<'a>
pub fn with_overwrite_source_translations( self, overwrite_source_translations: bool, ) -> UpdateCatalogOptions<'a>
Returns options that enable or disable source-locale translation refreshes.
Sourcepub fn with_now(self, now: &'a str) -> UpdateCatalogOptions<'a>
pub fn with_now(self, now: &'a str) -> UpdateCatalogOptions<'a>
Returns options that stamp newly obsolete entries with the given ISO date.
Trait Implementations§
Source§impl<'a> Clone for UpdateCatalogOptions<'a>
impl<'a> Clone for UpdateCatalogOptions<'a>
Source§fn clone(&self) -> UpdateCatalogOptions<'a>
fn clone(&self) -> UpdateCatalogOptions<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more