Skip to main content

parse_catalog

Function parse_catalog 

Source
pub fn parse_catalog(
    options: ParseCatalogOptions<'_>,
) -> Result<ParsedCatalog, ApiError>
Expand description

Parses catalog content into the higher-level representation used by ferrocat’s catalog APIs.

§Errors

Returns ApiError when the catalog content cannot be parsed, the source locale is missing, or strict ICU projection fails.

§Examples

use ferrocat_po::{ParseCatalogOptions, parse_catalog};

let catalog = parse_catalog(ParseCatalogOptions {
    locale: Some("de"),
    ..ParseCatalogOptions::new("msgid \"Checkout\"\nmsgstr \"Zur Kasse\"\n", "en")
})?;

assert_eq!(catalog.locale.as_deref(), Some("de"));
assert_eq!(catalog.messages.len(), 1);
Examples found in repository?
examples/runtime_compile.rs (lines 10-15)
6fn catalog(
7    content: &str,
8    locale: &str,
9) -> Result<NormalizedParsedCatalog, Box<dyn std::error::Error>> {
10    Ok(parse_catalog(ParseCatalogOptions {
11        content,
12        locale: Some(locale),
13        source_locale: "en",
14        ..ParseCatalogOptions::new("", "en")
15    })?
16    .into_normalized_view()?)
17}
More examples
Hide additional examples
examples/release_audit.rs (lines 7-12)
3fn catalog(
4    content: &str,
5    locale: &str,
6) -> Result<NormalizedParsedCatalog, Box<dyn std::error::Error>> {
7    Ok(ferrocat::parse_catalog(ParseCatalogOptions {
8        content,
9        locale: Some(locale),
10        source_locale: "en",
11        ..ParseCatalogOptions::new("", "en")
12    })?
13    .into_normalized_view()?)
14}