pub struct NormalizedParsedCatalog { /* private fields */ }Expand description
Parsed catalog with fast key-based lookup helpers.
Implementations§
Source§impl NormalizedParsedCatalog
impl NormalizedParsedCatalog
Sourcepub fn compile(
&self,
options: &CompileCatalogOptions<'_>,
) -> Result<CompiledCatalog, ApiError>
pub fn compile( &self, options: &CompileCatalogOptions<'_>, ) -> Result<CompiledCatalog, ApiError>
Compiles the normalized catalog into a runtime-oriented lookup map.
Compiled keys are derived from the canonical gettext identity
(msgctxt + msgid) using the selected built-in key strategy.
The default configuration keeps translations as-is without filling
missing values from the source text.
§Errors
Returns ApiError::InvalidArguments when source fallback is enabled
without a source_locale, or ApiError::Conflict when two source
messages compile to the same derived key.
use ferrocat_po::{CompileCatalogOptions, ParseCatalogOptions, parse_catalog};
let parsed = parse_catalog(ParseCatalogOptions {
content: "msgid \"Hello\"\nmsgstr \"Hallo\"\n",
source_locale: "en",
locale: Some("de"),
..ParseCatalogOptions::default()
})?;
let normalized = parsed.into_normalized_view()?;
let compiled = normalized.compile(&CompileCatalogOptions::default())?;
assert_eq!(compiled.len(), 1);
let (_, message) = compiled.iter().next().expect("compiled message");
assert_eq!(message.source_key.msgid, "Hello");Source§impl NormalizedParsedCatalog
impl NormalizedParsedCatalog
Sourcepub const fn parsed_catalog(&self) -> &ParsedCatalog
pub const fn parsed_catalog(&self) -> &ParsedCatalog
Returns the underlying parsed catalog.
Sourcepub fn into_parsed_catalog(self) -> ParsedCatalog
pub fn into_parsed_catalog(self) -> ParsedCatalog
Consumes the normalized view and returns the underlying parsed catalog.
Sourcepub fn get(&self, key: &CatalogMessageKey) -> Option<&CatalogMessage>
pub fn get(&self, key: &CatalogMessageKey) -> Option<&CatalogMessage>
Returns a message by key.
Sourcepub fn contains_key(&self, key: &CatalogMessageKey) -> bool
pub fn contains_key(&self, key: &CatalogMessageKey) -> bool
Returns true if a message for key exists.
Sourcepub fn message_count(&self) -> usize
pub fn message_count(&self) -> usize
Returns the number of indexed messages.
Sourcepub fn iter(
&self,
) -> impl Iterator<Item = (&CatalogMessageKey, &CatalogMessage)>
pub fn iter( &self, ) -> impl Iterator<Item = (&CatalogMessageKey, &CatalogMessage)>
Iterates over all indexed messages in key order.
Sourcepub fn effective_translation(
&self,
key: &CatalogMessageKey,
) -> Option<EffectiveTranslationRef<'_>>
pub fn effective_translation( &self, key: &CatalogMessageKey, ) -> Option<EffectiveTranslationRef<'_>>
Returns the effective translation for key, if present.
Sourcepub fn effective_translation_with_source_fallback(
&self,
key: &CatalogMessageKey,
source_locale: &str,
) -> Option<EffectiveTranslation>
pub fn effective_translation_with_source_fallback( &self, key: &CatalogMessageKey, source_locale: &str, ) -> Option<EffectiveTranslation>
Returns the effective translation and fills empty source-locale values from the source text when appropriate.
Trait Implementations§
Source§impl Clone for NormalizedParsedCatalog
impl Clone for NormalizedParsedCatalog
Source§fn clone(&self) -> NormalizedParsedCatalog
fn clone(&self) -> NormalizedParsedCatalog
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more