formatjs_intl
High-level Rust internationalization runtime. Owns message descriptors,
translation catalogs, ICU4X locale negotiation, and shared compiled-message
caching. Formatting delegates to formatjs_icu_messageformat.
message_descriptor! generates missing IDs with
[sha512:contenthash:base64:10]. Pass id: to keep a semantic ID.
use ;
use ;
use ;
const TASKS: MessageDescriptor = message_descriptor!;
let mut catalog = new;
catalog.insert?;
catalog.insert?;
let intl = try_new?;
let values: Values = from;
assert_eq!;
# Ok::
Use format_message! for inline application copy. It creates the same
descriptor, is recognized by formatjs extract, and returns a String:
# use Values;
# use ;
#
If cache infrastructure fails, this macro reports the error through
with_on_error and returns default_message verbatim. Fallible formatting
methods remain available when callers need explicit error handling.
Message formatting falls back from the selected locale catalog to the default
locale catalog, then the descriptor's default_message. Invalid translations
also use this chain. Attach with_on_error to observe recovered formatting and
infrastructure errors:
# use ;
#
Precompile catalogs with the FormatJS CLI to skip runtime message parsing:
Add serde_json to load the compiled catalog:
[]
= "1"
# use ;
let messages: PrecompiledMessages =
from_str?;
let mut catalog = new;
catalog.insert_precompiled?;
# Ok::
Precompiled messages are ready to format when inserted and do not use
IntlCache.
Requested locales must already be ordered by preference. HTTP
Accept-Language parsing stays in the application or web-framework adapter.