5 releases

0.0.5 Mar 12, 2023
0.0.4 Mar 8, 2023
0.0.3 Mar 7, 2023
0.0.2 Mar 7, 2023
0.0.1 Mar 4, 2023

#47 in Internationalization (i18n)

Download history 14/week @ 2023-02-27 79/week @ 2023-03-06 8/week @ 2023-03-13

101 downloads per month

MIT license

200KB
5K SLoC

rspolib

crates.io docs.rs

Port to Rust of the Python library polib.

Install

cargo add rspolib

Usage

use rspolib::pofile;

let po = pofile("path/to/file.po").unwrap();

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

po.save("path/to/other/file.po");

See the documentation at docs.rs/rspolib


Python bindings


lib.rs:

PO and MO files manipulation library.

Port to Rust of the Python library polib. The implementation differs a bit to make it even better.

Quick start

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

  • [POFile]s, contains [POEntry]s.
  • [MOFile]s, contains [MOEntry]s.

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 [MOEntry]s 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().

Dependencies

~1–1.5MB
~35K SLoC