Skip to main content

Crate ferrocat_icu

Crate ferrocat_icu 

Source
Expand description

Compact, performance-oriented ICU MessageFormat parsing primitives.

§Examples

use ferrocat_icu::{extract_variables, parse_icu};

let message = parse_icu("Hello {name}, you have {count, plural, one {# item} other {# items}}.")?;
assert_eq!(extract_variables(&message), vec!["name", "count"]);
use ferrocat_icu::{
    IcuCompatibilityOptions, analyze_icu, compare_icu_messages, parse_icu,
};

let source = parse_icu("Hello {name}, you have {count, number, integer} files.")?;
let translation = parse_icu("Hallo, du hast {count, number, integer} Dateien.")?;

let source_analysis = analyze_icu(&source);
assert_eq!(source_analysis.arguments.len(), 2);

let report = compare_icu_messages(
    &source,
    &translation,
    &IcuCompatibilityOptions::default(),
);
assert!(report.has_errors());
use ferrocat_icu::{
    MessageArgumentKind, MessageMetadataInput, normalize_message_metadata,
};

let metadata = normalize_message_metadata(MessageMetadataInput::new(
    "{count, plural, one {One item} other {# items}}",
))?;

assert_eq!(
    metadata.args.get("count").map(|argument| argument.kind),
    Some(MessageArgumentKind::Number)
);
assert!(metadata.selectors.contains_key("count"));

Structs§

IcuAnalysis
Structural summary of a parsed ICU message.
IcuArgument
One data argument reference discovered in an ICU message.
IcuCompatibilityOptions
Options controlling ICU source/translation compatibility checks.
IcuCompatibilityReport
Report returned by compare_icu_messages.
IcuDiagnostic
One diagnostic emitted by an ICU compatibility check.
IcuFormatter
One formatter reference discovered in an ICU message.
IcuMessage
Parsed ICU message.
IcuOption
A selector branch inside a plural or select expression.
IcuParseError
Error returned when parsing ICU messages fails.
IcuParserOptions
Options controlling ICU parsing behavior.
IcuPluralSummary
One cardinal or ordinal plural expression discovered in an ICU message.
IcuPosition
Byte offset plus line/column location inside the original input.
IcuSelectSummary
One select expression discovered in an ICU message.
IcuTagSummary
One rich-text tag discovered in an ICU message.
MessageArgumentFormatMetadata
Formatter metadata attached to an argument.
MessageArgumentMetadata
Normalized semantic metadata for one message argument.
MessageMetadata
Normalized semantic metadata for one source message.
MessageMetadataDiagnostic
One diagnostic emitted while validating semantic message metadata.
MessageMetadataInput
Authoring input for semantic message metadata.
MessageMetadataValidationReport
Report returned by validate_message_metadata.
MessageOriginMetadata
Extraction origin attached to semantic message metadata.
MessageSelectorMetadata
Selector metadata attached to a selecting argument.

Enums§

IcuArgumentKind
Broad role of an ICU argument in a parsed message.
IcuDiagnosticSeverity
Severity level attached to ICU authoring diagnostics.
IcuErrorKind
High-level classification of ICU parse failures.
IcuNode
AST node emitted by the ICU parser.
IcuPluralKind
Distinguishes cardinal and ordinal plural forms.
IcuStyleKind
Classification of an optional formatter style segment.
MessageArgumentKind
Broad argument kind used by semantic message metadata.
MessageArgumentMetadataInput
Progressive authoring input for one argument.
MessageFormatStyleKind
Classification of a message formatter style.
MessageSelectorKind
Selector kind used by semantic message metadata.

Functions§

analyze_icu
Produces a structural summary of a parsed ICU message.
compare_icu_messages
Compares source and translation ICU messages for authoring compatibility.
derive_message_metadata_from_icu
Derives normalized semantic metadata from an ICU MessageFormat v1 msgid.
extract_argument_names
Extracts data argument names in first-seen order, excluding rich-text tags.
extract_tag_names
Extracts rich-text tag names in first-seen order.
extract_variables
Extracts variable names in first-seen order.
has_plural
Returns true when the message contains a cardinal plural expression.
has_select
Returns true when the message contains a select expression.
has_selectordinal
Returns true when the message contains an ordinal plural expression.
has_tag
Returns true when the message contains rich-text style tags.
normalize_message_metadata
Normalizes progressive semantic message metadata into canonical object form.
parse_icu
Parses ICU MessageFormat input with the default parser options.
parse_icu_with_options
Parses ICU MessageFormat input with explicit parser options.
validate_icu
Validates ICU MessageFormat input without returning the parsed AST.
validate_message_metadata
Validates progressive semantic message metadata against its msgid.