Difference between revisions of "Tips For Python Script Extensions"

From Inkscape Wiki
Jump to navigation Jump to search
(Change default advices after v0.91)
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
==Adding Translation Capability==
==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 <tt>sys.stderr</tt>, use the provided <tt>errormsg()</tt> function from inkex.py in conjuction with <tt>gettext</tt>.
One can add the ability to have Python text messages included for translation. To provide an error message, rather than using the Python <tt>sys.stderr</tt>, use the provided <tt>errormsg()</tt> function from inkex.py in conjunction with <tt>gettext</tt>.


You must include the following at the beginning of your Python script:
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 inkex
  import gettext
  import gettext
Line 13: Line 17:
Of course, you may also change "_" to something else if you wish.
Of course, you may also change "_" to something else if you wish.


==Extensions on Mac OSX==
      sudo easy_install lxml
      cd /Applications/Inkscape.app/Contents/Resources/lib
      mv libxml2.2.dylib libxml2.2.dylib.old
      ln -s /usr/lib/libxml2.dylib
 
[[Category:Extensions]]
[[Category:Extensions]]

Revision as of 09:58, 13 March 2016

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.