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::
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 formatting errors while
returning the fallback:
# 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.