Struct poem::i18n::I18NBundle
source · [−]pub struct I18NBundle(_);
Available on crate feature
i18n
only.Expand description
A collection of localization messages.
Implementations
sourceimpl I18NBundle
impl I18NBundle
sourcepub fn text_with_args<'a>(
&self,
id: impl AsRef<str>,
args: impl Into<I18NArgs<'a>>
) -> Result<String, I18NError>
pub fn text_with_args<'a>(
&self,
id: impl AsRef<str>,
args: impl Into<I18NArgs<'a>>
) -> Result<String, I18NError>
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}"
);
sourcepub fn text(&self, id: impl AsRef<str>) -> Result<String, I18NError>
pub fn text(&self, id: impl AsRef<str>) -> Result<String, I18NError>
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more