GNOME Bugzilla – Bug 351287
review and internationalize gimp-python scripts
Last modified: 2006-09-21 14:28:24 UTC
If we want to install Python scripts with GIMP 2.4, they should appear in the users language, if possible. Currently, pygimp doesn't have i18n support and no strings are marked for translation. This needs to change. We should also review what python scripts are generally useful and which only copy existing functionality and/or are meant as examples. The latter scripts should not be installed (and also do not need to be marked for translation).
Settig on the 2.4 milestone and raising Priority because this would have to be done as soon as possible so that translators get a chance to do their work.
I have done some minor cleanups to the scripts in preparation of i18n.
Created attachment 72684 [details] [review] Translates most of the strings in gimpcons.py and gtkcons.py "Does this mean that noone is interested in having the existing Python scripts in GIMP 2.4?" The console is the only interesting one from my point of view. Though the others serve somewhat well as examples. I say 'most' because I wasn't sure whether error messages as in: def tell(self): raise IOError, (29, 'Illegal seek') should be translated, so I didn't mark them. The usage of gettext is extremely simplistic. I've marked the translatable strings just like they are marked in C code : _("Translatable String content") (after earlier doing 'from gettext import gettext as _') . I suspect that I need to set a text domain via gettext.textdomain() but I have no idea what it should be.
We need to introduce a new domain for this. This will probably be called gimp20-python. We also have to figure out if intltool can handle python or if we need to use pyxgettext for this.
Intltool gettext can handle python, yes.
I tested this and indeed, we can use intltool for this. I will add the necessary framework to CVS, I am also attaching a modified version of David's patch. This one is less agressive about marking strings for translation. Some of the marked strings were not at all displayed anywhere in the UI and some should probably not be translated.
Created attachment 72715 [details] [review] less agressive change for gtkcons.py and gimpcons.py
The basic framework for preparing the translations in the gimp20-python domain is now in CVS: 2006-09-13 Sven Neumann <sven@gimp.org> * Makefile.am * configure.in * po-python: added basic infrastructure for a gimp20-python translation domain. * plug-ins/pygimp/plug-ins/gimpcons.py * plug-ins/pygimp/plug-ins/gtkcons.py: mark some strings for translation, based on a patch from David Gowers (bug #351287).
For this to actually work, we still need to do something like this: import gettext t = gettext.translation('gimp20-python', gimp.locale_directory) _ = t.ugettext However we do not want to include such code all over the place. It should probably go into the gimpui module but I haven't yet figured out how to do this.
I did some more changes and i18n now works for strings in the pygimp module. The plug-ins itself are however not yet properly internationalized. For this to work the plug-in has to register the translation domain with GIMP and call an equivalent to INIT_I18N(). Still not sure how that would be done best.
The usual pratice when making a python plug-in is importing the gimp bindings by doing: from gimpfu import * That menas tht binding "_" to the transalsting function in the gimpfu.py namespace would sufice. However, most third part party plug-ins also do that (from gimpfu import *) ) and doing that means that "_" would be pointing to the pygimp translating domain in all those plug-ins. I think that creating a very small python module, with little more (if more) than the 3 lines in #9 above - possibly called "pygimp_i18n" and in all plug-ins add a "from pygimp_i18n import *" line.
I found a solution that works nicely (IMO). The only remaining issue is that one cannot specify the location of the textdomain with the current API. I will look into fixing this but this is only an issue for third-party Python plug-ins. 2006-09-15 Sven Neumann <sven@gimp.org> * plug-ins/pygimp/gimpmodule.c: added domain_register method. * plug-ins/pygimp/gimpfu.py: define N_(). Added an optional "domain" parameter to the register() method. Register the domain with GIMP and initialize gettext if it is specified. * plug-ins/pygimp/plug-ins/gimpcons.py: use N_() to mark menu label and blurb for translation. Specify the translation domain. * plug-ins/pygimp/plug-ins/gtkcons.py: use gettext API for modules. Now that the framework is implemented, we only need someone to go over the plug-ins, review strings and mark them for translation. gimpcons.py can serve as an example.
Some minor refinements: 2006-09-16 Manish Singh <yosh@gimp.org> * plug-ins/pygimp/gimpfu.py * plug-ins/pygimp/plug-ins/gtkcons.py: let the gettext module * po-python/POTFILES.in * plug-ins/pygimp/gimpui.py: Mark a couple strings for translation here.
Fixed the remaining issue with the framework (not being able to specify the locale directory): 2006-09-19 Sven Neumann <sven@gimp.org> * plug-ins/pygimp/gimpfu.py: allow to pass a (domain, path) tuple as value for the domain argument of the register() call. Document the domain argument.
I have prepared all plug-ins for translation and did some minor cleanups, mostly string changes. The changed plug-ins probably need some more testing but I think we can now close this bug-report now.