#translation #framework #parser #gettext #catalog #plural #ng

gettext-ng

A tweaked implementation of Gettext translation framework for Rust for NG's projects

1 unstable release

0.4.1 Jan 10, 2023

#279 in Internationalization (i18n)

21 downloads per month
Used in usdpl-back

MIT license

38KB
871 lines

Gettext for Rust

Documentation (latest stable)

Roadmap for now

  • Parsing MO files (10.3)
  • Parsing metadata (6.2)
  • Supporting encodings other than UTF-8
  • Parsing the plural expression (11.2.6)
  • Correct pathfinding? (11.2.3)

lib.rs:

This crate is a reimplementation of GNU gettext translation framework in Rust. It allows your Rust programs to parse out GNU MO files containing translations and use them in your user interface.

It contains several differences from the official C implementation. Notably, this crate does not in any way depend on a global locale (2.2) and does not enforce a directory structure for storing your translation catalogs (11.2.3). Instead, the choice of translation catalog to use is explicitly made by the user.

This crate is still in-progress and may not be on par with the original implementation feature-wise.

For the exact feature parity see the roadmap in the README.

Example


use std::fs::File;
use gettext::Catalog;

fn main() {
    let f = File::open("french.mo").expect("could not open the catalog");
    let catalog = Catalog::parse(f).expect("could not parse the catalog");

    // Will print out the French translation
    // if it is found in the parsed file
    // or "Name" otherwise.
    println!("{}", catalog.gettext("Name"));
}

Dependencies

~2.5MB
~32K SLoC