Thursday, 8 October 2009

gettext - Edit text within GUI elements

Say you want to change arbitrary text within a GUI element, the little pop-up that tells you when new updates are available for instance. You want it to say 'The following updates will be installed when you shut down your computer' instead of 'The following updates are available' or something. It's remarkably straightforward.

A lot of the internationalization (or is it localization?) within Linux GUI elements is handled by gettext .mo files, which list the translations of text elements for all the supported languages. In our example, the GUI element we want to change is part of the Fedora package gnome-packagekit. The English translations for the gnome-packagekit package are kept in /usr/share/locale/en_GB/LC_MESSAGES/gnome-packagekit.mo. To change the text for a specific element, you have to unpack the file using msgunfmt, edit it with poedit, then repack it with msgfmt. Like this:

1) Find the gettext file containing the text you want to change. In Fedora, they're filed by language in /usr/share/locale/ - grep is your friend here.

2) Unpack the file:

cp /usr/share/locale/en_GB/LC_MESSAGES/gnome-packagekit.mo /usr/share/locale/en_GB/LC_MESSAGES/gnome-packagekit.mo.bak
msgunfmt /usr/share/locale/en_GB/LC_MESSAGES/gnome-packagekit.mo > ~/gnome-packagekit.po

2) Edit the file. Search for the text you want to change, and change it:


poedit ~/gnome-packagekit.po

3) Repack the gettext file:

msgfmt -v -o /usr/share/locale/en_GB/LC_MESSAGES/gnome-packagekit.mo ~/gnome-packagekit.po

Bob's your uncle.

No comments:

Post a Comment