Localisation of rust applications

Travis Build Status

This repository is an attempt to make it possible to localize rust application. There are two crates

How to translate a rust application

  1. Annotate the strings in your source code with the write macro/functions. You can use

  2. Run the xtr program over your crate to extract the string in a .pot file

  3. Use the GNU gettext tools to merge, translate, and generate the .mo files

About tr!

Future plans

Example

```Rust

[macro_use]

extern crate tr; fn main() { // use the trinit macro to tell gettext where to look for translations trinit!("/usr/share/locale/"); let folder = if let Some(folder) = std::env::args().nth(1) { folder } else { println!("{}", tr!("Please give folder name")); return; }; match std::fs::read_dir(&folder) { Err(e) => { println!("{}", tr!("Could not read directory '{}'\nError: {}", folder, e)); } Ok(r) => { // Singlular/plural formating println!("{}", tr!( "The directory {} has one file" | "The directory {} has {n} files" % r.count(), folder )); } } } ```

About xtr

xtr is a tool that extract translated strings from the source code of a rust crate. The tool is supposed to be compatible with any gettext based functions. But support for the special syntax of the tr! macro has been added.

Usage

xtr src/main.rs -o example.pot

This will extract the strings from all the modules of the crate, and create a file example.pot. You can now use the gettext tools to translate this file.

Differences with xgettext

xtr is basically to be used in place of xgettext for Rust code. xgettext does not currently support the rust language. We can get decent result using the C language, but:

Licence

Contribution

Contributions are welcome. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, should be licensed under the MIT license.

Request for feedback

Please fill your suggestions as issues. Or help by commenting on https://github.com/woboq/tr/issues/1