pub struct Catalog { /* private fields */ }
Expand description
Catalog represents a set of translation strings parsed out of one MO file.
Implementations
sourceimpl Catalog
impl Catalog
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.
Currently, the only supported plural formula is n != 1
.
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.
Currently, the only supported plural formula is n != 1
.