Difference between revisions of "Tips For Python Script Extensions"

From Inkscape Wiki
Jump to navigation Jump to search
m (Undo revision 84290 by Jingshaochen (talk) not the preferred solution for the official package of Inkscape for Mac OS X which includes all needed modules)
Line 7: Line 7:
  import gettext
  import gettext
  _ = gettext.gettext
  _ = gettext.gettext
Note: Changes are likely to occur in 0.49. To enable messages translation, you will have to include the following lines instead:
import inkex
inkex.localize()


Where you wish to have an error message, write the following:
Where you wish to have an error message, write the following:

Revision as of 11:07, 18 July 2012

Adding Translation Capability

One can add the ability to have Python text mesages included for translation. To provide an error message, rather than using the Python sys.stderr, use the provided errormsg() function from inkex.py in conjuction with gettext.

You must include the following at the beginning of your Python script:

import inkex
import gettext
_ = gettext.gettext

Note: Changes are likely to occur in 0.49. To enable messages translation, you will have to include the following lines instead:

import inkex
inkex.localize()

Where you wish to have an error message, write the following:

inkex.errormsg(_("This will be written to Python stderr"))

Of course, you may also change "_" to something else if you wish.