pub struct Locale {Show 16 fields
pub locale: String,
pub dates: DateTerms,
pub roles: HashMap<ContributorRole, ContributorTerm>,
pub locators: HashMap<LocatorType, LocatorTerm>,
pub terms: Terms,
pub punctuation_in_quote: bool,
pub sort_articles: Vec<String>,
pub locale_schema_version: Option<String>,
pub evaluation: EvaluationConfig,
pub messages: HashMap<String, String>,
pub date_formats: HashMap<String, String>,
pub number_formats: NumberFormats,
pub grammar_options: GrammarOptions,
pub legacy_term_aliases: HashMap<String, String>,
pub vocab: VocabMap,
pub evaluator: Arc<dyn MessageEvaluator>,
}Expand description
A locale definition containing language-specific terms and formatting rules.
The evaluator field holds the message evaluation engine, selected based on
evaluation.message_syntax. This allows for trait-based swapping to ICU4X
implementations in the future without changing call sites.
Fields§
§locale: StringThe locale identifier (e.g., “en-US”, “de-DE”).
dates: DateTermsDate-related terms (months, seasons).
roles: HashMap<ContributorRole, ContributorTerm>Contributor role terms (editor, translator, etc.).
locators: HashMap<LocatorType, LocatorTerm>Locator terms (page, chapter, etc.).
terms: TermsGeneral terms (and, et al., etc.).
punctuation_in_quote: boolWhether to place periods/commas inside quotation marks. true = American style (“text.”), false = British style (“text”.)
sort_articles: Vec<String>Articles to strip from titles when sorting (e.g., “the”, “a”, “an” for English). These should be lowercase and will be matched case-insensitively.
locale_schema_version: Option<String>Schema version from the source locale file (None = legacy v1).
evaluation: EvaluationConfigRuntime evaluation configuration.
messages: HashMap<String, String>ICU MF1 messages keyed by message ID (populated for v2 locales).
date_formats: HashMap<String, String>Named date format presets: symbolic name → CLDR pattern.
number_formats: NumberFormatsNumber formatting options.
grammar_options: GrammarOptionsGrammar options.
legacy_term_aliases: HashMap<String, String>Backwards-compatibility aliases: old term key → new message ID.
vocab: VocabMapVocabulary maps for genre and medium display text.
evaluator: Arc<dyn MessageEvaluator>Message evaluator implementation (not serialized; set during load).
Implementations§
Source§impl Locale
impl Locale
Sourcepub fn strip_sort_articles<'a>(&self, s: &'a str) -> &'a str
pub fn strip_sort_articles<'a>(&self, s: &'a str) -> &'a str
Strip leading articles from a string for sorting.
Uses locale-specific articles (e.g., “the”, “a”, “an” for English; “der”, “die”, “das” for German). Falls back to English articles if no locale-specific articles are defined.
Sourcepub fn lookup_genre(&self, key: &str) -> String
pub fn lookup_genre(&self, key: &str) -> String
Look up display text for a genre canonical key.
Falls back to a readable form of the key if no translation found.
Sourcepub fn lookup_medium(&self, key: &str) -> String
pub fn lookup_medium(&self, key: &str) -> String
Look up display text for a medium canonical key.
Falls back to a readable form of the key if no translation found.
Sourcepub fn role_term(
&self,
role: &ContributorRole,
plural: bool,
form: &TermForm,
requested_gender: Option<GrammaticalGender>,
) -> Option<&str>
pub fn role_term( &self, role: &ContributorRole, plural: bool, form: &TermForm, requested_gender: Option<GrammaticalGender>, ) -> Option<&str>
Get a contributor role term.
Sourcepub fn role_term_neutral(
&self,
role: &ContributorRole,
plural: bool,
form: &TermForm,
) -> Option<&str>
pub fn role_term_neutral( &self, role: &ContributorRole, plural: bool, form: &TermForm, ) -> Option<&str>
Resolve a contributor role term using only neutral/common values.
Sourcepub fn resolved_role_term(
&self,
role: &ContributorRole,
plural: bool,
form: &TermForm,
requested_gender: Option<GrammaticalGender>,
) -> Option<String>
pub fn resolved_role_term( &self, role: &ContributorRole, plural: bool, form: &TermForm, requested_gender: Option<GrammaticalGender>, ) -> Option<String>
Resolve a contributor role term, evaluating MF2 messages when configured.
Sourcepub fn resolved_role_term_neutral(
&self,
role: &ContributorRole,
plural: bool,
form: &TermForm,
) -> Option<String>
pub fn resolved_role_term_neutral( &self, role: &ContributorRole, plural: bool, form: &TermForm, ) -> Option<String>
Resolve a contributor role term using only neutral/common values.
Sourcepub fn locator_term(
&self,
locator: &LocatorType,
plural: bool,
form: &TermForm,
requested_gender: Option<GrammaticalGender>,
) -> Option<&str>
pub fn locator_term( &self, locator: &LocatorType, plural: bool, form: &TermForm, requested_gender: Option<GrammaticalGender>, ) -> Option<&str>
Get a locator term.
Sourcepub fn resolved_locator_term(
&self,
locator: &LocatorType,
plural: bool,
form: &TermForm,
requested_gender: Option<GrammaticalGender>,
) -> Option<String>
pub fn resolved_locator_term( &self, locator: &LocatorType, plural: bool, form: &TermForm, requested_gender: Option<GrammaticalGender>, ) -> Option<String>
Resolve a locator term, evaluating MF2 messages when configured.
Sourcepub fn general_term(
&self,
term: &GeneralTerm,
form: &TermForm,
requested_gender: Option<GrammaticalGender>,
) -> Option<&str>
pub fn general_term( &self, term: &GeneralTerm, form: &TermForm, requested_gender: Option<GrammaticalGender>, ) -> Option<&str>
Resolve a general term to a borrowed string.
Sourcepub fn resolved_general_term(
&self,
term: &GeneralTerm,
form: &TermForm,
requested_gender: Option<GrammaticalGender>,
) -> Option<String>
pub fn resolved_general_term( &self, term: &GeneralTerm, form: &TermForm, requested_gender: Option<GrammaticalGender>, ) -> Option<String>
Resolve a general term, evaluating MF2 messages when configured.
Sourcepub fn resolved_archive_term(
&self,
field: ArchiveHierarchyField,
) -> Option<String>
pub fn resolved_archive_term( &self, field: ArchiveHierarchyField, ) -> Option<String>
Resolve an archive hierarchy label, using MF2 messages. Returns singular form (count=1) by default.
Sourcepub fn month_name(&self, month: u8, short: bool) -> &str
pub fn month_name(&self, month: u8, short: bool) -> &str
Get a month name.
Sourcepub fn resolve_date_pattern(
&self,
message_id: &str,
year: Option<&str>,
month: Option<&str>,
day: Option<u32>,
) -> Option<String>
pub fn resolve_date_pattern( &self, message_id: &str, year: Option<&str>, month: Option<&str>, day: Option<u32>, ) -> Option<String>
Resolve a pattern.date-* message with locale-specific year/month/day
components.
Returns Some(rendered) only when the locale carries an MF2 message
at message_id and the evaluator produces output. Callers fall back
to the engine’s hardcoded English assembly on None.
A component is forwarded to the evaluator only when non-empty; an
authored pattern that references {$day} therefore yields None if
the input date carries no day, letting the caller pick a shorter form.
The day argument is taken as Option<u32> rather than a pre-formatted
string so the digit-to-string allocation is deferred until after the
message lookup succeeds — the common case for legacy locales (en-US,
every v1 file) is the lookup miss, which now incurs zero allocation.
Source§impl Locale
impl Locale
Sourcepub fn from_yaml_str(yaml: &str) -> Result<Locale, String>
pub fn from_yaml_str(yaml: &str) -> Result<Locale, String>
Load a locale from a YAML string.
§Errors
Returns an error when the YAML cannot be parsed into a locale.
Sourcepub fn load(locale_id: &str, locales_dir: &Path) -> Locale
pub fn load(locale_id: &str, locales_dir: &Path) -> Locale
Load a locale by ID (e.g., “en-US”, “de-DE”) from a locales directory. Falls back to en-US if the locale file is not found.
Sourcepub fn from_file(path: &Path) -> Result<Locale, String>
pub fn from_file(path: &Path) -> Result<Locale, String>
Load locale from a file path directly (detects format).
§Errors
Returns an error when the file cannot be read or its contents cannot be parsed as a supported locale format.
Sourcepub fn parse_general_term(name: &str) -> Option<GeneralTerm>
pub fn parse_general_term(name: &str) -> Option<GeneralTerm>
Parse a locale term key into a structured general-term identifier.
Sourcepub fn apply_override(&mut self, ov: &LocaleOverride)
pub fn apply_override(&mut self, ov: &LocaleOverride)
Apply a partial override, merging its fields into this locale.
Performs key-by-key insertion or replacement for:
messages: new or updated message IDsgrammar_options: ifSome, replaces the entire block and syncspunctuation_in_quotefieldlegacy_term_aliases: new or updated term aliases