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.
- IcuCompatibility
Options - Options controlling ICU source/translation compatibility checks.
- IcuCompatibility
Report - 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.
- IcuParse
Error - Error returned when parsing ICU messages fails.
- IcuParser
Options - Options controlling ICU parsing behavior.
- IcuPlural
Summary - One cardinal or ordinal plural expression discovered in an ICU message.
- IcuPosition
- Byte offset plus line/column location inside the original input.
- IcuSelect
Summary - One select expression discovered in an ICU message.
- IcuTag
Summary - One rich-text tag discovered in an ICU message.
- Message
Argument Format Metadata - Formatter metadata attached to an argument.
- Message
Argument Metadata - Normalized semantic metadata for one message argument.
- Message
Metadata - Normalized semantic metadata for one source message.
- Message
Metadata Diagnostic - One diagnostic emitted while validating semantic message metadata.
- Message
Metadata Input - Authoring input for semantic message metadata.
- Message
Metadata Validation Report - Report returned by
validate_message_metadata. - Message
Origin Metadata - Extraction origin attached to semantic message metadata.
- Message
Selector Metadata - Selector metadata attached to a selecting argument.
Enums§
- IcuArgument
Kind - Broad role of an ICU argument in a parsed message.
- IcuDiagnostic
Severity - Severity level attached to ICU authoring diagnostics.
- IcuError
Kind - High-level classification of ICU parse failures.
- IcuNode
- AST node emitted by the ICU parser.
- IcuPlural
Kind - Distinguishes cardinal and ordinal plural forms.
- IcuStyle
Kind - Classification of an optional formatter style segment.
- Message
Argument Kind - Broad argument kind used by semantic message metadata.
- Message
Argument Metadata Input - Progressive authoring input for one argument.
- Message
Format Style Kind - Classification of a message formatter style.
- Message
Selector Kind - 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
truewhen the message contains a cardinal plural expression. - has_
select - Returns
truewhen the message contains a select expression. - has_
selectordinal - Returns
truewhen the message contains an ordinal plural expression. - has_tag
- Returns
truewhen the message contains rich-text style tags. - normalize_
message_ metadata - Normalizes progressive semantic message metadata into canonical object form.
- parse_
icu - Parses ICU
MessageFormatinput with the default parser options. - parse_
icu_ with_ options - Parses ICU
MessageFormatinput with explicit parser options. - validate_
icu - Validates ICU
MessageFormatinput without returning the parsed AST. - validate_
message_ metadata - Validates progressive semantic message metadata against its
msgid.