Skip to main content

Crate rspolib

Crate rspolib 

Source
Expand description

crates.io PyPI docs.rs Bindings docs

Port to Rust of the Python library polib.

§Install

cargo add rspolib

§Usage

use rspolib::{pofile, prelude::*};

let po = pofile("./tests-data/flags.po").unwrap();

for entry in &po.entries {
    println!("{}", entry.msgid);
}

po.save("./file.po");

See the documentation at docs.rs/rspolib

§Python bindings

Python versions

§Quick examples

§Read and save a PO file

use rspolib::{pofile, Save};

let file = pofile("tests-data/obsoletes.po").unwrap();
for entry in file.translated_entries() {
    println!("{}", &entry.msgid);
}
file.save("tests-data/docs/pofile_save.po");

§Read and save a MO file

// You can include the prelude to access to all the methods
use rspolib::{mofile, prelude::*};

let mut file = mofile("tests-data/all.mo").unwrap();
for entry in &file.entries {
    // All entries are translated in MO files
    println!("{}", entry.msgid);
}
file.save("tests-data/docs/mofile_save.mo");

§Features

  • Unicode Line Breaking formatting support.
  • Correct handling of empty and non existent PO fields values.
  • Detailed error handling parsing PO and MO files.
  • Custom byte order MO files generation.

§General view

Items of the same level can be converted between them, for example a POEntry can be converted to a MOEntry using MOEntry::from(&POEntry) because MOEntrys implement the From trait for &POEntry.

All of the conversions that make sense are implemented for all the structs. For example, to get the representation of a POFile just call to_string() or to get the binary representation of bytes of a MOFile calls as_bytes().

Modules§

errors
Errors generated by the parsers
prelude
rspolib prelude

Structs§

EntryCmpByOptions
A struct to compare two entries.
FileOptions
File options struct passed when creating a new PO or MO file
MOEntry
MO file entry representing a message
MOFile
MO file
POEntry
PO file entry representing a message
POFile
PO file

Constants§

MAGIC
Magic number of little endian mo files encoding
MAGIC_SWAPPED
Magic number of big endian mo files encoding

Traits§

AsBytes
Provides functions to convert to MO files content as bytes
Merge
Merge entries and files
MsgidEotMsgctxt
Concatenates msgid + EOT + msgctxt
Save
Save file with the save method
SaveAsMOFile
Save file as a MO file with the save_as_mofile method
SaveAsPOFile
Save file as a PO file with the save_as_pofile method
TranslatedEntry
Provides a function translated to represent if an entry struct is translated

Functions§

mo_metadata_entry_to_string
Converts a metadata wrapped by a MOEntry to a string representation.
mofile
MO files factory function
po_metadata_entry_to_string
Converts a metadata wrapped by a POEntry to a string representation.
pofile
PO files factory function.