pub struct Messages {
pub collection: HashMap<String, HashMap<String, String>>,
}
Expand description
The object that keeps the messages collection.
This is the yaml file to be used in the following tests:
## tests/en/messages.yaml
hello:
world: Hello World!
somebody: Hello {user}!
Fields§
§collection: HashMap<String, HashMap<String, String>>
Implementations§
Source§impl Messages
impl Messages
Sourcepub fn new(source: &str) -> Messages
pub fn new(source: &str) -> Messages
Creates and returns the Messages
instance given the messages root folder path.
§Examples:
use kalgan_i18n::Messages;
let messages: Messages = Messages::new("tests");
Sourcepub fn trans(
&self,
language: &str,
message_id: &str,
parameters: HashMap<&str, String>,
) -> String
pub fn trans( &self, language: &str, message_id: &str, parameters: HashMap<&str, String>, ) -> String
Returns the translated message for the given parameters.
§Examples:
use kalgan_i18n::Messages;
assert_eq!(messages.trans("en", "hello.world", HashMap::new()), "Hello World!");
use kalgan_i18n::Messages;
let mut parameters = HashMap::new();
parameters.insert("user", "John".to_string());
assert_eq!(messages.trans("en", "hello.somebody", parameters), "Hello John!");
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Messages
impl RefUnwindSafe for Messages
impl Send for Messages
impl Sync for Messages
impl Unpin for Messages
impl UnwindSafe for Messages
Blanket Implementations§
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