Struct rspolib::POFile

source ·
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: bool

Whether the metadata is marked with the fuzzy flag or not.

§options: FileOptions

Options defined for the file. See FileOptions.

Implementations§

source§

impl POFile

source

pub fn new(options: FileOptions) -> Self

source

pub fn remove(&mut self, entry: &POEntry)

Remove an entry from the file

source

pub fn remove_by_msgid(&mut self, msgid: &str)

Remove the first entry that has the same msgid

source

pub fn remove_by_msgid_msgctxt(&mut self, msgid: &str, msgctxt: &str)

Remove the first entry that has the same msgid and msgctxt

source

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:

  • msgid
  • msgstr
  • msgctxt
  • msgid_plural
  • previous_msgid
  • previous_msgid_plural
  • previous_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.

source

pub fn find_by_msgid(&self, msgid: &str) -> Option<POEntry>

Find an entry by his msgid

source

pub fn find_by_msgid_msgctxt(&self, msgid: &str, msgctxt: &str) -> Option<POEntry>

Find an entry by msgid and msgctxt

source

pub fn percent_translated(&self) -> f32

Returns the percent of the entries translated in the file

source

pub fn translated_entries(&self) -> Vec<&POEntry>

Returns references to the translated entries of the file

source

pub fn untranslated_entries(&self) -> Vec<&POEntry>

Returns references to the untranslated entries of the file

source

pub fn obsolete_entries(&self) -> Vec<&POEntry>

Returns references to the obsolete entries of the file

source

pub fn fuzzy_entries(&self) -> Vec<&POEntry>

Returns references to the fuzzy entries of the file

source

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

source§

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>

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>

Return the PO file content as a bytes vector of the MO file version with big endianess

source§

impl Clone for POFile

source§

fn clone(&self) -> POFile

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for POFile

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for POFile

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> From<&'a str> for POFile

source§

fn from(path_or_content: &'a str) -> Self

Converts to this type from the input type.
source§

impl From<&POFile> for MOFile

source§

fn from(file: &POFile) -> MOFile

Converts to this type from the input type.
source§

impl From<Vec<&POEntry, Global>> for POFile

source§

fn from(entries: Vec<&POEntry>) -> Self

Converts to this type from the input type.
source§

impl Merge for POFile

source§

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

source§

fn eq(&self, other: &POFile) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Save for POFile

source§

fn save(&self, path: &str)

Save the PO file as the given path

source§

impl SaveAsMOFile for POFile

source§

fn save_as_mofile(&self, path: &str)

Save the PO file as a MO file as the given path

source§

impl SaveAsPOFile for POFile

source§

fn save_as_pofile(&self, path: &str)where Self: Display,

Save the file as a PO file to the given path
source§

impl StructuralPartialEq for POFile

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.