4 stable releases

1.1.2 May 9, 2024
1.1.1 Mar 24, 2022
1.1.0 Mar 21, 2022
1.0.6 Jan 20, 2022
1.0.5 Dec 1, 2021

#175 in Internationalization (i18n)

Download history 7/week @ 2024-07-22 12/week @ 2024-07-29 6/week @ 2024-08-05 8/week @ 2024-08-12 7/week @ 2024-08-19 18/week @ 2024-08-26 13/week @ 2024-09-02 13/week @ 2024-09-09 17/week @ 2024-09-16 68/week @ 2024-09-23 27/week @ 2024-09-30 1/week @ 2024-10-07 9/week @ 2024-10-14 10/week @ 2024-10-21 19/week @ 2024-10-28 17/week @ 2024-11-04

55 downloads per month
Used in 3 crates

MIT license

180KB
4K SLoC

Crates.io Docs.rs CircleCI Coverage Status

poreader

Rust library for reading translation catalogs in Uniforum/Gettext PO. Similar to the translate.storage package in Python Translate Toolkit.

Only PO and Xliff are planned to be supported. For anything else, just convert it with Translate Toolkit. There is no point in replacing that excellent library; the main reason for Rust parser and writer is to them as part of build process of Rust programs, especially in procedural macros, which need to be written in Rust.

Documentation

On Docs.rs.

Installation

It uses Cargo, Rust's package manager. You can depend on this library by adding poreader to your Cargo dependencies:

[dependencies]
poreader = "1.1"

Or, to use the Git repo directly:

[dependencies.poreader]
git = "https://github.com/corebreaker/poreader.git"

How to use

Start by creating a PO reader from a new PO parser, then iterate on the reader:

use poreader::PoParser;

use std::{env::args, fs::File, io::{Result, Error, ErrorKind}};

struct NoArg;
impl std::error::Error for NoArg {}

impl std::fmt::Display for NoArg {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { std::fmt::Debug::fmt(self, f) }
}

impl std::fmt::Debug for NoArg {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "No file specified") }
}

fn main() -> Result<()> {
    // Filename
    let filename = match args().skip(1).next() {
        Some(v) => v,
        None => { return Err(Error::new(ErrorKind::Other, NoArg)); }
    };

    // Open a file
    let file = File::open(filename)?;

    // Create PO parser
    let parser = PoParser::new();
    
    // Create PO reader
    let reader = parser.parse(file)?;

    // Read PO file by iterating on units
    for unit in reader {
        let unit = unit?;

        // Show `msgid`
        println!(" - {}", unit.message().get_id())
    }

    Ok(())
}

Status of the project

The project works for instance.

Future changes is directely related to the change of the format of the PO file.

However, it would be updated with a need from contributors. You can post an issue or a pull request if you see something that can be improved.

Dependencies

~2.9–5.5MB
~87K SLoC