#[non_exhaustive]pub struct CompileCatalogArtifactOptions<'a> {
pub requested_locale: &'a str,
pub source_locale: &'a str,
pub fallback_chain: &'a [&'a str],
pub key_strategy: CompiledKeyStrategy,
pub source_fallback: bool,
pub strict_icu: bool,
pub icu_compatibility: bool,
pub semantics: CatalogSemantics,
pub icu_options: CompileCatalogArtifactIcuOptions,
}catalog only.Expand description
Options controlling high-level compiled catalog artifact generation.
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.requested_locale: &'a strLocale for which the runtime artifact should be produced.
source_locale: &'a strSource locale used for explicit source fallback behavior.
fallback_chain: &'a [&'a str]Ordered fallback locales consulted after the requested locale.
key_strategy: CompiledKeyStrategyBuilt-in strategy used to derive stable runtime keys.
source_fallback: boolWhether source text should be used when no non-source translation exists.
strict_icu: boolWhether invalid final ICU messages should fail compilation instead of producing diagnostics.
icu_compatibility: boolWhether final ICU messages should be checked against source ICU structure.
semantics: CatalogSemanticsHigh-level semantics used by the input catalog set.
icu_options: CompileCatalogArtifactIcuOptionsICU-specific options used while validating final runtime messages.
Implementations§
Source§impl<'a> CompileCatalogArtifactOptions<'a>
impl<'a> CompileCatalogArtifactOptions<'a>
Sourcepub fn new(
requested_locale: &'a str,
source_locale: &'a str,
) -> CompileCatalogArtifactOptions<'a>
pub fn new( requested_locale: &'a str, source_locale: &'a str, ) -> CompileCatalogArtifactOptions<'a>
Creates artifact compile options with required locales set.
Optional fields default to an empty fallback chain, FerrocatV1 keys,
no source fallback, non-strict ICU diagnostics, no ICU compatibility
check, and ICU-native semantics.
Examples found in repository?
16fn main() -> Result<(), Box<dyn std::error::Error>> {
17 let source = catalog(
18 "msgid \"Checkout\"\nmsgstr \"Checkout\"\n\nmsgid \"Cart\"\nmsgstr \"Cart\"\n",
19 "en",
20 )?;
21 let german = catalog("msgid \"Checkout\"\nmsgstr \"Zur Kasse\"\n", "de")?;
22
23 let options = CompileCatalogArtifactOptions::new("de", "en").with_source_fallback(true);
24 let artifact = compile_catalog_artifact(&[&source, &german], &options)?;
25
26 assert_eq!(artifact.messages.len(), 2);
27 assert_eq!(artifact.missing.len(), 1);
28 assert!(artifact.messages.values().any(|value| value == "Zur Kasse"));
29 assert!(artifact.messages.values().any(|value| value == "Cart"));
30
31 for (key, value) in &artifact.messages {
32 println!("{key} = {value}");
33 }
34
35 Ok(())
36}Sourcepub fn with_requested_locale(
self,
requested_locale: &'a str,
) -> CompileCatalogArtifactOptions<'a>
pub fn with_requested_locale( self, requested_locale: &'a str, ) -> CompileCatalogArtifactOptions<'a>
Returns options that compile the given requested locale.
Sourcepub fn with_source_locale(
self,
source_locale: &'a str,
) -> CompileCatalogArtifactOptions<'a>
pub fn with_source_locale( self, source_locale: &'a str, ) -> CompileCatalogArtifactOptions<'a>
Returns options that use the given source locale.
Sourcepub fn with_fallback_chain(
self,
fallback_chain: &'a [&'a str],
) -> CompileCatalogArtifactOptions<'a>
pub fn with_fallback_chain( self, fallback_chain: &'a [&'a str], ) -> CompileCatalogArtifactOptions<'a>
Returns options that consult the given ordered fallback locales.
Sourcepub fn with_key_strategy(
self,
key_strategy: CompiledKeyStrategy,
) -> CompileCatalogArtifactOptions<'a>
pub fn with_key_strategy( self, key_strategy: CompiledKeyStrategy, ) -> CompileCatalogArtifactOptions<'a>
Returns options that derive runtime keys with the given strategy.
Sourcepub fn with_source_fallback(
self,
source_fallback: bool,
) -> CompileCatalogArtifactOptions<'a>
pub fn with_source_fallback( self, source_fallback: bool, ) -> CompileCatalogArtifactOptions<'a>
Returns options that enable or disable source-text fallback.
Examples found in repository?
16fn main() -> Result<(), Box<dyn std::error::Error>> {
17 let source = catalog(
18 "msgid \"Checkout\"\nmsgstr \"Checkout\"\n\nmsgid \"Cart\"\nmsgstr \"Cart\"\n",
19 "en",
20 )?;
21 let german = catalog("msgid \"Checkout\"\nmsgstr \"Zur Kasse\"\n", "de")?;
22
23 let options = CompileCatalogArtifactOptions::new("de", "en").with_source_fallback(true);
24 let artifact = compile_catalog_artifact(&[&source, &german], &options)?;
25
26 assert_eq!(artifact.messages.len(), 2);
27 assert_eq!(artifact.missing.len(), 1);
28 assert!(artifact.messages.values().any(|value| value == "Zur Kasse"));
29 assert!(artifact.messages.values().any(|value| value == "Cart"));
30
31 for (key, value) in &artifact.messages {
32 println!("{key} = {value}");
33 }
34
35 Ok(())
36}Sourcepub fn with_strict_icu(
self,
strict_icu: bool,
) -> CompileCatalogArtifactOptions<'a>
pub fn with_strict_icu( self, strict_icu: bool, ) -> CompileCatalogArtifactOptions<'a>
Returns options that enable or disable hard errors for invalid final ICU messages.
Sourcepub fn with_icu_compatibility(
self,
icu_compatibility: bool,
) -> CompileCatalogArtifactOptions<'a>
pub fn with_icu_compatibility( self, icu_compatibility: bool, ) -> CompileCatalogArtifactOptions<'a>
Returns options that enable or disable final ICU compatibility checks.
Sourcepub fn with_semantics(
self,
semantics: CatalogSemantics,
) -> CompileCatalogArtifactOptions<'a>
pub fn with_semantics( self, semantics: CatalogSemantics, ) -> CompileCatalogArtifactOptions<'a>
Returns options that interpret input catalogs with the given semantics.
Sourcepub fn with_icu_options(
self,
icu_options: CompileCatalogArtifactIcuOptions,
) -> CompileCatalogArtifactOptions<'a>
pub fn with_icu_options( self, icu_options: CompileCatalogArtifactIcuOptions, ) -> CompileCatalogArtifactOptions<'a>
Returns options that use the given ICU parser and formatter-support settings.
Trait Implementations§
Source§impl<'a> Clone for CompileCatalogArtifactOptions<'a>
impl<'a> Clone for CompileCatalogArtifactOptions<'a>
Source§fn clone(&self) -> CompileCatalogArtifactOptions<'a>
fn clone(&self) -> CompileCatalogArtifactOptions<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a> Debug for CompileCatalogArtifactOptions<'a>
impl<'a> Debug for CompileCatalogArtifactOptions<'a>
impl<'a> Eq for CompileCatalogArtifactOptions<'a>
Source§impl<'a> PartialEq for CompileCatalogArtifactOptions<'a>
impl<'a> PartialEq for CompileCatalogArtifactOptions<'a>
Source§fn eq(&self, other: &CompileCatalogArtifactOptions<'a>) -> bool
fn eq(&self, other: &CompileCatalogArtifactOptions<'a>) -> bool
self and other values to be equal, and is used by ==.