On Mon, Jul 16, 2012 at 9:48 PM, Amy C <mathematical.cof...@gmail.com> wrote: > Hi all, > > I asked this question a while ago (maybe a week or so?), although I've > been trying to work this out for a couple of months. Well, I just > worked out how to do it so I thought I'd share in case anyone else > wants to know. > > I've got an extension that provides a window menu from the appMenu > almost identical to the one you get by right-clicking a window's > system title bar: with 'Minimize', 'Maximize', 'Move', ... > > Now I wanted to add translations, but since the strings in my menu are > identical to those in the system right-click menu, I felt that rather > than starting from scratch and having to rely on the good will of > translators to re-translate all the strings for me, I should just use > the translations from the "system". > > After a lot of searching I realised that that right-click menu is > handled by either Metacity or Mutter, being the window manager. So I > looked in the Mutter source (in the 'po') directory at en_GB.po > (translation file), and noticed a whole bunch of strings to be > translated: > > Ma_ximize > Mi_nimize > _Resize > _Move > > and so on. Exactly what I want (the _ are for keyboard accelerators). > > Once I discovered this, it's simply a matter of adding the following > lines (well in 3.2 anyhow, I imagine it's much the same in 3.4): > > const Gettext = imports.gettext.domain('mutter'); // I want to use the > mutter translations > const _ = Gettext.gettext; > > log(_("Mi_nimize")); // Voila! It translates!! > > So after ages of wondering how to do this, it boils down to really > just finding the right domain to use with gettext (which was a bit of > educated guessing - first that the system window menu would be handled > by the window manager, and then downloading the source to look at the > po files). > > (I did also take the additional step of removing the underscores since > they appear as literal underscores if used in a PopupMenuItem. If a > language legitimately uses underscores as characters then the > translated string will be missing them, but hopefully there aren't too > many of those. > > Also, I'm tossing up whether to keep using the mutter translations or > to create my own translations (just copying the relevant lines from > the mutter .po files) which allows me to at least add the possibility > of extra translated strings that are not in the mutter source, like > 'Raise window', or 'Window options'.)
You can certainly use the domain from mutter and from your extension at the same time: const Gettext = imports.gettext; const _ = Gettext.gettext; const M_ = Gettext.domain('mutter').gettext; function init() { Gettext.bindtextdomain('window-options@...'); } > Also, to test a translation quickly you can go in the terminal and do: > > export LANG=it_IT.utf8 # for example italian > gjs # start gjs console > const Gettext = imports.gettext.domain('mutter'); // use mutter translations > // if you are using your own domain not in the system locale directory, > // you probably need some sort of > bindtextdomain('mydomain','/path/to/locale/dir') > const _ = Gettext.gettext; > _("Maximize Window") > // "Massimizza la finestra" > > (I just do it in the console to keep the language changes to that one > terminal session instead of affecting my global session). > > Hope this helps someone some time in the future! > _______________________________________________ > gnome-shell-list mailing list > gnome-shell-list@gnome.org > https://mail.gnome.org/mailman/listinfo/gnome-shell-list -- Jasper _______________________________________________ gnome-shell-list mailing list gnome-shell-list@gnome.org https://mail.gnome.org/mailman/listinfo/gnome-shell-list