Crate pobuilder

Source
Expand description

Translation catalogues are key part of any localization infrastructure. They contain the lists of messages from the application, possibly disambiguated with identifiers or contexts, and corresponding translations.

Catalogs are usually stored in one of two formats: Portable Objects (.po), used primarily by GNU gettext, and XML Localisation Interchange File Format (XLIFF), a more generic OASIS open standard.

These formats can be converted to each other, and to and from many others, using translate-toolkit.

XLIFF is quite flexible and can be used in different ways, but this library focuses primarily on using it in a way gettext and translate-toolkit work, namely with separate catalogue for each language.

Example:

use pobuilder::PoParser;

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

fn main() -> Result<()> {
    // Filename
    let filename = match args().skip(1).next() {
        Some(v) => v,
        None => {
            eprintln!("No file specified");

            return Ok(());
        }
    };

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

    // Create PO parser
    let builder = PoParser::new();

    // Parse the file
    let pofile = builder.parse(file)?;

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

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

    Ok(())
}

Modules§

comment
error
note
plural
unit

Structs§

PoFile
Object for managing PO streams
PoParser
Object used for the creation of a PO reader

Enums§

Message
String wrapper possibly with plural variants.
Origin
Note (comment) origins.
State
Translation state.

Traits§

CatalogueReader
Catalogue reader.