Struct poem::i18n::I18NBundle
source · pub struct I18NBundle(/* private fields */);
Available on crate feature
i18n
only.Expand description
A collection of localization messages.
Implementations§
source§impl 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 Freeze for I18NBundle
impl !RefUnwindSafe for I18NBundle
impl Send for I18NBundle
impl Sync for I18NBundle
impl Unpin for I18NBundle
impl !UnwindSafe for I18NBundle
Blanket Implementations§
source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> TowerCompatExt for T
impl<T> TowerCompatExt for T
source§fn compat<ResBody, Err, Fut>(self) -> TowerCompatEndpoint<Self>where
ResBody: Body + Send + Sync + 'static,
ResBody::Data: Into<Bytes> + Send + 'static,
ResBody::Error: StdError + Send + Sync + 'static,
Err: Into<Error>,
Self: Service<Request<BoxBody<Bytes, Error>>, Response = Response<ResBody>, Error = Err, Future = Fut> + Clone + Send + Sync + Sized + 'static,
Fut: Future<Output = Result<Response<ResBody>, Err>> + Send + 'static,
fn compat<ResBody, Err, Fut>(self) -> TowerCompatEndpoint<Self>where
ResBody: Body + Send + Sync + 'static,
ResBody::Data: Into<Bytes> + Send + 'static,
ResBody::Error: StdError + Send + Sync + 'static,
Err: Into<Error>,
Self: Service<Request<BoxBody<Bytes, Error>>, Response = Response<ResBody>, Error = Err, Future = Fut> + Clone + Send + Sync + Sized + 'static,
Fut: Future<Output = Result<Response<ResBody>, Err>> + Send + 'static,
Available on crate feature
tower-compat
only.Converts a tower service to a poem endpoint.