A common way for people to boost their language skills is to set the locale of their computer to the target language they want to learn.
Using programs when you don't know many words can be a frustrating experience unless you can easily look up the translation when needed.
The following is a guide for how to do this on Linux based operating systems like Ubuntu.
The following article offers a good overview for how internationalization works on Ubuntu works for many open source programs.
The key points from that article are:
- many programs use another program called
gettext
to look up translations - these translations are stored in
.mo
files, which are binary and meant for machines .po
files are human-readable, created by translators, and then processed into.mo
files for use by programs.
Performing Translation: An Example With GIMP
Consider the following example for translating "Image", one of the options in the menu bar for GIMP, into Greek.
We can use the same gettext
program that GIMP uses to perform the translation.
$ gettext --help ⏎
gettext [OPTION] [[TEXTDOMAIN] MSGID]
...
We need the following three pieces of information:
- The text domain (
TEXTDOMAN
) - and the message id (
MSGID
) - the language we want to translate to (i.e. Greek)
- This will be passed as a
LANGUAGE
environment variable whichgettext
reads.
- This will be passed as a
First, for the text domain, find GIMP translation files by running the following command:
$ sudo find / -type f -name '*gimp*.mo' 2>/dev/null ⏎
...
/snap/gimp/380/usr/share/locale/el/LC_MESSAGES/gimp20.mo
...
Note: 2>/dev/null
is a common way to filter out errors like "Permission Denied".
This will output the translation files for all the various languages like Greek (el
).
From the article mentioned at the beginning, the text domain is the name of the .mo
file (i.e. gimp20
).
The message ID, by convention, is simply the word or phrase in English. In this example, Image
.
To acquire the target language, list the various locales installed on your machine:
$ locale -a ⏎
el_GR.utf8
en_US.utf8
el_GR.utf8
is Greek, while en_US.utf8
is the US dialect of English.
For more information, see this article.
Finally, combine all 3 elements in the final command to translate "Image" into Greek the same way GIMP would.
$ LANGUAGE=el_GR.utf8 gettext gimp20 Image ⏎
Εικόνα
The reverse process, translating from Greek into English, is not as straight-forward.
It requires converting the .mo
file back into a .po
file using a program called msgunfmt
.
First, ensure the msgunfmt
program is installed.
If you see "command not found", then see this website and execute the command appropriate for your operating system.
For Ubuntu, you may need to run:
sudo apt-get install gettext
Using the msgunfmt
program is simple. Just pass the name of the .mo
file as the first and only argument.
$ msgunfmt /snap/gimp/380/usr/share/locale/el/LC_MESSAGES/gimp20.mo ⏎
This will output the translations in a human-readable format, like it would exist as a .po
file.
Then we can pipe the output into grep
with the Greek word we want to look up (i.e. Εικόνα
).
$ msgunfmt /snap/gimp/380/usr/share/locale/el/LC_MESSAGES/gimp20.mo | grep -B 1 "Εικόνα" ⏎
...
msgid "Image"
msgstr "Εικόνα"
...
Note: -B 1
is to display the previous line (e.g. 'msgid "Image"').