Skip to main content

UpdateCatalogOptions

Struct UpdateCatalogOptions 

Source
#[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>, }
Available on crate feature catalog only.
Expand description

Options for in-memory catalog updates.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional 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 str

Source locale used for source-side semantics and fallback handling.

§input: CatalogUpdateInput

Extracted messages to merge into the catalog.

§existing: Option<&'a str>

Existing catalog content, when updating an in-memory catalog.

§mode: CatalogMode

High-level catalog mode used when parsing, merging, and rendering the catalog.

§obsolete_strategy: ObsoleteStrategy

Strategy for messages absent from the extracted input.

§overwrite_source_translations: bool

Whether 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>

Source

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?
crates/ferrocat/examples/fcl_with_mt_metadata.rs (line 18)
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}
Source

pub fn with_locale(self, locale: &'a str) -> UpdateCatalogOptions<'a>

Returns options that use the given catalog locale.

Examples found in repository?
crates/ferrocat/examples/fcl_with_mt_metadata.rs (line 19)
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}
Source

pub fn with_existing(self, existing: &'a str) -> UpdateCatalogOptions<'a>

Returns options that update the given existing catalog content.

Examples found in repository?
crates/ferrocat/examples/fcl_with_mt_metadata.rs (line 21)
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}
Source

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?
crates/ferrocat/examples/fcl_with_mt_metadata.rs (line 20)
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}
Source

pub fn with_render(self, render: RenderOptions<'a>) -> UpdateCatalogOptions<'a>

Returns options that render the updated catalog with the given options.

Source

pub fn with_obsolete_strategy( self, obsolete_strategy: ObsoleteStrategy, ) -> UpdateCatalogOptions<'a>

Returns options that handle missing extracted messages with the given strategy.

Source

pub fn with_overwrite_source_translations( self, overwrite_source_translations: bool, ) -> UpdateCatalogOptions<'a>

Returns options that enable or disable source-locale translation refreshes.

Source

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>

Source§

fn clone(&self) -> UpdateCatalogOptions<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for UpdateCatalogOptions<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'a> Eq for UpdateCatalogOptions<'a>

Source§

impl<'a> PartialEq for UpdateCatalogOptions<'a>

Source§

fn eq(&self, other: &UpdateCatalogOptions<'a>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for UpdateCatalogOptions<'a>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.