Internationalization of Fractal (part 1)

It is the beginning of the coding period and I will first work on investigating on implementing the internationalization of Fractal and then find a way to do it. At this moment, internationalization support in Rust is limited and new, so no GTK application written in Rust have implemented it yet. And it is very exciting to work on this with this perspective, furthermore because I will write some blogposts that will try to explain how to do it and I hope it could help other people to do so!

Internationalization (i18n) vs localization (l10n)

Internationalization (i18n) is the process of implementing the support of localization within an application. Localization (l10n) is the act of translating (usually from English) every messages used in the UI of an application into another language and to use the conventions (dates, units, number representations) of a country.

i18n is done by using a framework that will make it easy for translators to write localizations of an application. GNOME applications use gettext in order to do so.

A brief introduction to gettext

gettext is a framework and a set of utilities that aims at helping with internationalization and localization. For example, you adapt your source code like this from

println!("Hello world");

to

println!("{}", gettext("Hello world"));

so that the string “Hello world” will replaced with its translation at run time. We first use the utility xgettext to extract every translatable strings from a source file. xgettext will generate a POT (Portable Object Tamplate) file from which we will derive into a PO (Portable Object) file for each language where we will write the translation of each string. Then the PO files will be compiled into MO (Machine Object) files that can be used by gettext at runtime to fetch the translation of the translatable strings. So PO and MO file are basically tables that maps each English string to its translation.

gettext and Rust

I have checked what are the options for using gettext with Rust. At this moment, there are two Rust bindings available for gettext but both of the crates on crates.io are two years old (gettext and gettext-rs). However, gettext-rs’s GitHub repository has been updated again between December 2017 and March 2018 so we can use the latest version by putting (in Cargo.toml)

gettext-rs = { git = "https://github.com/Koka/gettext-rs", features = ["gettext-system"] }

instead of

gettext-rs = "0.3.0"

Using this seems to be the best thing to use for now.

The plan for achieving this

I will first try to test gettext-rs with a simple textual program, then find out how to translate strings in a GTK program’s source code and XML files. When this will be done, I will be able to implement the i18n in Fractal. However, I will also have to investigate about the distribution of the MO files and adding the text extraction to the meson script to be able to generate new translations.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s