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

#89 in Internationalization (i18n)

Download history 6020/week @ 2023-11-07 5811/week @ 2023-11-14 3802/week @ 2023-11-21 5297/week @ 2023-11-28 3807/week @ 2023-12-05 2988/week @ 2023-12-12 3734/week @ 2023-12-19 2480/week @ 2023-12-26 2219/week @ 2024-01-02 2516/week @ 2024-01-09 3723/week @ 2024-01-16 3661/week @ 2024-01-23 4016/week @ 2024-01-30 4184/week @ 2024-02-06 5787/week @ 2024-02-13 5325/week @ 2024-02-20

19,909 downloads per month
Used in 12 crates (11 directly)

MIT license

37KB
852 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