pobuilder

Crates.iopobuilder
lib.rspobuilder
version0.1.0
sourcesrc
created_at2024-10-28 21:30:22.845347
updated_at2024-10-28 21:30:22.845347
descriptionBuild or modify translation catalogs in PO format.
homepage
repositoryhttps://github.com/corebreaker/pobuilder
max_upload_size
id1426099
size190,876
Frédéric Meyer (corebreaker)

documentation

https://docs.rs/pobuilder

README

Crates.io Docs.rs CircleCI Coverage Status

pobuilder

Rust library for forging and for parsing translation catalogs forked from the crate poreader.

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 pobuilder to your Cargo dependencies:

[dependencies]
pobuilder = "0.1"

Or, to use the Git repo directly:

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

Or, finally by Cargo CLI:

cargo add pobuilder

How to use

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

use pobuilder::PoParser;

use std::{
    fmt::{Debug, Display, Formatter, Result as FmtResult},
    io::{Result, Error as IoError, ErrorKind},
    error::Error as StdError,
    env::args,
    fs::File,
};

struct NoArg;
impl StdError for NoArg {}

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

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

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

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

    // Create PO parser
    let parser = PoParser::new()?;
    
    // Parse the opened file
    let pofile = parser.parse(file)?;

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

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

    Ok(())
}

Status of the project

This project is in early development stage. It's a fork of the crate poreader, which is a parser for PO files.

The writer was suggested by the crate poreader, in an issue, here, but it was never implemented.

Commit count: 2

cargo fmt