Tips For Python Script Extensions

From Inkscape Wiki
Revision as of 03:10, 15 December 2019 by Patrick87 (talk | contribs) (Superseded by inkex API introduced in Inkscape 1.0)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

This page is outdated. It is kept for historical reasons, e.g. to document specific decisions in Inkscape development.

Adding Translation Capability

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

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

import inkex
inkex.localize()

Note: In prior versions (0.49), you will have to include the following lines instead:

import inkex
import gettext
_ = gettext.gettext

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.