Struct poem::i18n::I18NBundle
source · [−]pub struct I18NBundle(_);
This is supported 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 T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
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
sourceimpl<T> FutureExt for T
impl<T> FutureExt for T
sourcefn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
sourcefn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more