4 releases (breaking)

0.4.0 Jun 4, 2019
0.3.0 Nov 14, 2018
0.2.0 Mar 14, 2016
0.1.0 Feb 9, 2016

#100 in Internationalization (i18n)

Download history 4148/week @ 2024-07-28 7627/week @ 2024-08-04 4778/week @ 2024-08-11 5491/week @ 2024-08-18 3413/week @ 2024-08-25 4854/week @ 2024-09-01 4596/week @ 2024-09-08 7054/week @ 2024-09-15 8295/week @ 2024-09-22 6580/week @ 2024-09-29 8068/week @ 2024-10-06 5584/week @ 2024-10-13 7400/week @ 2024-10-20 6637/week @ 2024-10-27 4986/week @ 2024-11-03 3397/week @ 2024-11-10

22,679 downloads per month
Used in 14 crates (12 directly)

MIT license

41KB
964 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