Crates.io | pobuilder |
lib.rs | pobuilder |
version | 0.1.0 |
source | src |
created_at | 2024-10-28 21:30:22.845347 |
updated_at | 2024-10-28 21:30:22.845347 |
description | Build or modify translation catalogs in PO format. |
homepage | |
repository | https://github.com/corebreaker/pobuilder |
max_upload_size | |
id | 1426099 |
size | 190,876 |
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.
On Docs.rs.
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
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(())
}
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.