1 unstable release
0.4.1 | Jan 10, 2023 |
---|
#298 in Internationalization (i18n)
94 downloads per month
Used in usdpl-back
38KB
871 lines
Gettext for Rust
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