pub struct POFile {
pub entries: Vec<POEntry>,
pub header: Option<String>,
pub metadata: HashMap<String, String>,
pub metadata_is_fuzzy: bool,
pub options: FileOptions,
}Expand description
PO file
Fields§
§entries: Vec<POEntry>Entries of the file.
header: Option<String>Header of the file, if any. Optionally defined in PO files before the first entry.
metadata: HashMap<String, String>First optional field of PO files that describes the metadata of the file stored as a hash map.
metadata_is_fuzzy: boolWhether the metadata is marked with the fuzzy
flag or not.
options: FileOptionsOptions defined for the file. See FileOptions.
Implementations§
source§impl POFile
impl POFile
pub fn new(options: FileOptions) -> Self
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 find(
&self,
value: &str,
by: &str,
msgctxt: Option<&str>,
include_obsolete_entries: bool
) -> Vec<&POEntry>
pub fn find( &self, value: &str, by: &str, msgctxt: Option<&str>, include_obsolete_entries: bool ) -> Vec<&POEntry>
Find entries by a given field and value
The field defined in the by argument can be one of:
msgidmsgstrmsgctxtmsgid_pluralprevious_msgidprevious_msgid_pluralprevious_msgctxt
Passing the optional msgctxt argument the entry
will also must match with the given context.
If include_obsolete_entries is set to true the
search will include obsolete entries.
sourcepub fn find_by_msgid(&self, msgid: &str) -> Option<POEntry>
pub fn find_by_msgid(&self, msgid: &str) -> Option<POEntry>
Find an entry by his msgid
sourcepub fn find_by_msgid_msgctxt(&self, msgid: &str, msgctxt: &str) -> Option<POEntry>
pub fn find_by_msgid_msgctxt(&self, msgid: &str, msgctxt: &str) -> Option<POEntry>
Find an entry by msgid and msgctxt
sourcepub fn percent_translated(&self) -> f32
pub fn percent_translated(&self) -> f32
Returns the percent of the entries translated in the file
sourcepub fn translated_entries(&self) -> Vec<&POEntry>
pub fn translated_entries(&self) -> Vec<&POEntry>
Returns references to the translated entries of the file
sourcepub fn untranslated_entries(&self) -> Vec<&POEntry>
pub fn untranslated_entries(&self) -> Vec<&POEntry>
Returns references to the untranslated entries of the file
sourcepub fn obsolete_entries(&self) -> Vec<&POEntry>
pub fn obsolete_entries(&self) -> Vec<&POEntry>
Returns references to the obsolete entries of the file
sourcepub fn fuzzy_entries(&self) -> Vec<&POEntry>
pub fn fuzzy_entries(&self) -> Vec<&POEntry>
Returns references to the fuzzy entries of the file
sourcepub fn metadata_as_entry(&self) -> POEntry
pub fn metadata_as_entry(&self) -> POEntry
Returns the metadata of the file as an entry.
This method is not really useful because the
to_string() version will not be guaranteed to be
correct.
If you want to manipulate the metadata, change
the content of the field metadata in the file.
If you still want to render a metadata entry as a string, use the function po_metadata_entry_to_string:
use rspolib::{
pofile,
po_metadata_entry_to_string,
};
let file = pofile("tests-data/metadata.po").unwrap();
let entry = file.metadata_as_entry();
let entry_str = po_metadata_entry_to_string(&entry, true);
assert!(entry_str.starts_with("#, fuzzy\nmsgid \"\""));Trait Implementations§
source§impl AsBytes for POFile
impl AsBytes for POFile
source§fn as_bytes(&self) -> Vec<u8>
fn as_bytes(&self) -> Vec<u8>
Return the PO file content as a bytes vector of the MO file version
The MO file is encoded with little endian magic number and revision number 0
Use directly MOFile::as_bytes_with to customize the magic number and revision number:
use rspolib::{pofile, MAGIC_SWAPPED, MOFile};
let file = pofile("tests-data/all.po").unwrap();
let bytes = MOFile::from(&file).as_bytes_with(MAGIC_SWAPPED, 1);source§fn as_bytes_le(&self) -> Vec<u8>
fn as_bytes_le(&self) -> Vec<u8>
Return the PO file content as a bytes vector of the MO file version
Just an alias for POFile::as_bytes, for consistency with MOFile.
source§fn as_bytes_be(&self) -> Vec<u8>
fn as_bytes_be(&self) -> Vec<u8>
Return the PO file content as a bytes vector of the MO file version with big endianess
source§impl Merge for POFile
impl Merge for POFile
source§fn merge(&mut self, other: POFile)
fn merge(&mut self, other: POFile)
Merge another PO file into this one and return a new one
Recursively calls merge on each entry if they are found
in the current file searching by msgid and msgctxt. If not
found, generates a new entry.
This method is commonly used to merge a POT reference file with a PO file.
source§impl PartialEq<POFile> for POFile
impl PartialEq<POFile> for POFile
source§impl SaveAsMOFile for POFile
impl SaveAsMOFile for POFile
source§fn save_as_mofile(&self, path: &str)
fn save_as_mofile(&self, path: &str)
Save the PO file as a MO file as the given path