I’m writing a small program (javascript, but I don’t think it matters) and am trying to add translations to it.
The only strings in it that need to be translated are ‘Minimize’, ‘Maximize’, ‘Restore’, ‘Close’ etc — these should already have translations somewhere, right? Since when I right-click on a window’s system title bar I get a menu with these very same options (I’m using Linux).
Is there some way I can use these already-done translations instead of having to do them again (which involves me finding a whole bunch of translators happy to volunteer some time for the translation)?
Is it simply a matter of finding the right gettext domain? This is how I set it up at the moment (it is in javascript, but this is really irrelevant to the question):
const Gettext = imports.gettext.domain('foobar-gettext-domain');
const _ = Gettext.gettext;
OK, so on further reflection, I realised that I know how to use a pre-existing translation in gettext. To use a pre-existing text domain
asdf, just doNo surprises there.
It turned out that my actual problem was I wanted to use the translations for “Minimize”, “Maximize”, “Restore”, “Close”, etc, and I though I was sure these translations already existed on my system somewhere, I didn’t know what gettext domain they were actually in.
To find this out:
On Fedora (my version anyway), translated texts are in
/usr/share/locale.I went into
/usr/share/locale/en_GB/LC_MESSAGESand there are a bunch of.mofiles there. These are not human-readable but I can still grep through them:Looking through the list, it occured to me that since I’m looking for translations of items on a window menu, it’s probably my window manager that owns those translations. My window manager (as I’m on gnome-shell) is
mutter, which is based ofmetacity.So, I downloaded the mutter sources and looked in the
pofile (human-readable translation files), and lo and behold!So now that I’ve found the translations, it was simply a case of doing (in my code):
(I have to feed in
_("Ma_ximize")to gettext because that is the exact string that is translated in themutter.mofile — there is no"Maximize"translation without the underscore. I had to remove the underscores from the translated text after, which might screw up languages that use underscores as part of their writing somehow, but I’m hoping that’s not many).So, in summary — it’s easy to use another (pre-existing) text domain, but the problem is finding the text domain that has the strings you want.