Struct poem::i18n::I18NBundle
source[−]pub struct I18NBundle(_);
This is supported on crate feature
i18n
only.Expand description
A collection of localization messages.
Implementations
Gets the text with arguments.
Example
use poem::i18n::I18NResources;
use unic_langid::langid;
let resources = I18NResources::builder()
.add_ftl(
"en-US",
"input-parse-error = Error: Could not parse input `{ $input }`. Reason: { $reason }",
)
.build()
.unwrap();
let bundle = resources.negotiate_languages(&[langid!("en-US")]);
let err = "abc".parse::<i32>().unwrap_err();
assert_eq!(
bundle
.text_with_args(
"input-parse-error",
(("input", "abc"), ("reason", err.to_string()))
)
.unwrap(),
"Error: Could not parse input `\u{2068}abc\u{2069}`. Reason: \u{2068}invalid digit found in string\u{2069}"
);
Gets the text.
Example
use poem::i18n::I18NResources;
use unic_langid::langid;
let resources = I18NResources::builder()
.add_ftl("en-US", "hello-world = Hello world!")
.build()
.unwrap();
let bundle = resources.negotiate_languages(&[langid!("en-US")]);
assert_eq!(bundle.text("hello-world").unwrap(), "Hello world!");
Auto Trait Implementations
impl !RefUnwindSafe for I18NBundle
impl Send for I18NBundle
impl Sync for I18NBundle
impl Unpin for I18NBundle
impl !UnwindSafe for I18NBundle
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more