logo
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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Attaches the provided Context to this type, returning a WithContext wrapper. Read more

Attaches the current Context to this type, returning a WithContext wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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