pub struct Catalog { /* private fields */ }
Expand description
Catalog represents a set of translation strings parsed out of one MO file.
Implementations§
Source§impl Catalog
impl Catalog
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Creates an empty catalog.
All the translated strings will be the same as the original ones.
Sourcepub fn parse<R: Read>(reader: R) -> Result<Self, Error>
pub fn parse<R: Read>(reader: R) -> Result<Self, Error>
Parses a gettext catalog from the given binary MO file.
Returns the Err
variant upon encountering an invalid file format
or invalid byte sequence in strings.
Calling this method is equivalent to calling
ParseOptions::new().parse(reader)
.
§Examples
use gettext::Catalog;
use std::fs::File;
let file = File::open("french.mo").unwrap();
let catalog = Catalog::parse(file).unwrap();
Sourcepub fn gettext<'a>(&'a self, msg_id: &'a str) -> &'a str
pub fn gettext<'a>(&'a self, msg_id: &'a str) -> &'a str
Returns the singular translation of msg_id
from the given catalog
or msg_id
itself if a translation does not exist.
Sourcepub fn ngettext<'a>(
&'a self,
msg_id: &'a str,
msg_id_plural: &'a str,
n: u64,
) -> &'a str
pub fn ngettext<'a>( &'a self, msg_id: &'a str, msg_id_plural: &'a str, n: u64, ) -> &'a str
Returns the plural translation of msg_id
from the given catalog
with the correct plural form for the number n
of objects.
Returns msg_id if a translation does not exist and n == 1
,
msg_id_plural otherwise.
Sourcepub fn pgettext<'a>(&'a self, msg_context: &'a str, msg_id: &'a str) -> &'a str
pub fn pgettext<'a>(&'a self, msg_context: &'a str, msg_id: &'a str) -> &'a str
Returns the singular translation of msg_id
in the context msg_context
or msg_id
itself if a translation does not exist.
Sourcepub fn npgettext<'a>(
&'a self,
msg_context: &'a str,
msg_id: &'a str,
msg_id_plural: &'a str,
n: u64,
) -> &'a str
pub fn npgettext<'a>( &'a self, msg_context: &'a str, msg_id: &'a str, msg_id_plural: &'a str, n: u64, ) -> &'a str
Returns the plural translation of msg_id
in the context msg_context
with the correct plural form for the number n
of objects.
Returns msg_id if a translation does not exist and n == 1
,
msg_id_plural otherwise.