pub struct MOFile {
pub magic_number: Option<u32>,
pub version: Option<u32>,
pub metadata: HashMap<String, String>,
pub entries: Vec<MOEntry>,
pub options: FileOptions,
}
Expand description
MO file
Fields§
§magic_number: Option<u32>
Magic number, either MAGIC or MAGIC_SWAPPED
version: Option<u32>
Version number, either 0 or 1
metadata: HashMap<String, String>
Metadata as a hash map
entries: Vec<MOEntry>
Message entries
options: FileOptions
File options. See FileOptions.
Implementations§
source§impl MOFile
impl MOFile
pub fn new(options: FileOptions) -> Self
sourcepub fn metadata_as_entry(&self) -> MOEntry
pub fn metadata_as_entry(&self) -> MOEntry
Returns the metadata as a MOEntry
sourcepub fn find(
&self,
value: &str,
by: &str,
msgctxt: Option<&str>
) -> Vec<&MOEntry>
pub fn find( &self, value: &str, by: &str, msgctxt: Option<&str> ) -> Vec<&MOEntry>
Find entries by a given field and value
The field defined in the by
argument can be one of:
msgid
msgstr
msgctxt
msgid_plural
Passing the optional msgctxt
argument the entry
will also must match with the given context.
sourcepub fn find_by_msgid(&self, msgid: &str) -> Option<&MOEntry>
pub fn find_by_msgid(&self, msgid: &str) -> Option<&MOEntry>
Find an entry by msgid
sourcepub fn find_by_msgid_msgctxt(
&self,
msgid: &str,
msgctxt: &str
) -> Option<&MOEntry>
pub fn find_by_msgid_msgctxt( &self, msgid: &str, msgctxt: &str ) -> Option<&MOEntry>
Find an entry by msgid and msgctxt
sourcepub fn remove_by_msgid(&mut self, msgid: &str)
pub fn remove_by_msgid(&mut self, msgid: &str)
Remove the first entry that has the same msgid
sourcepub fn remove_by_msgid_msgctxt(&mut self, msgid: &str, msgctxt: &str)
pub fn remove_by_msgid_msgctxt(&mut self, msgid: &str, msgctxt: &str)
Remove the first entry that has the same msgid and msgctxt
sourcepub fn as_bytes_with(
&self,
magic_number: u32,
revision_number: u32
) -> Cow<'_, [u8]>
pub fn as_bytes_with( &self, magic_number: u32, revision_number: u32 ) -> Cow<'_, [u8]>
Returns the entry as a bytes vector
Specify the magic number and the revision number of the generated MO version of the file.
This method does not check the validity of the values
magic_number
and revision_version
to allow the
experimental developing of other revision of MO files,
so be careful about the passed values if you use it.
Valid values for the magic number are MAGIC and MAGIC_SWAPPED. Valid values for the revision number are 0 and 1.
Example
use rspolib::mofile;
let file = mofile("tests-data/all.mo").unwrap();
let bytes = file.as_bytes_with(rspolib::MAGIC_SWAPPED, 1);
assert_eq!(bytes.len(), 1327);
Trait Implementations§
source§impl PartialEq for MOFile
impl PartialEq for MOFile
source§impl SaveAsMOFile for MOFile
impl SaveAsMOFile for MOFile
source§fn save_as_mofile(&self, path: &str)
fn save_as_mofile(&self, path: &str)
Save the MOFile to a file at the given path