Extensions: Translations in inkex.py fail unless extension script itself initalizes gettext

Bug #1538277 reported by su_v on 2016-01-26
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Inkscape
Medium
jazzynico

Bug Description

Messages in inkex.py marked for translation (with '_()') cause the script / extension to abort with 'NameError' unless the extension which imports inkex does run 'inkex.localize()' (currently, only extensions which themselves need gettext for translated messages do this).

Steps to reproduce:
1) apply attached diff to $PREFIX/share/inkscape/extensions/inkex.py
2) launch Inkscape 0.91 or trunk
3) apply an extension which runs 'inkex.localize()':
Extensions > Render > Alphabet Soup
--> success: renders and returns "This is a test" as expected
4) apply an extension which does not run 'inkex.localize()':
Extensions > Render > Gear > Gear
--> failure:

Traceback (most recent call last):
  File "render_gears.py", line 184, in <module>
    e.affect()
  File "$PREFIX/share/inkscape/extensions/inkex.py", line 267, in affect
    self.parse()
  File "$PREFIX/share/inkscape/extensions/inkex.py", line 165, in parse
    errormsg(_("This is a test"))
NameError: global name '_' is not defined

Possible workaround / fix:
Run 'localize()' early on in the definition of 'affect()' instead of delegating this to individual extensions?

Reproduced with Inkscape 0.91 and 0.91+devel r14615 on OS X 10.7.5.

su_v (suv-lp) wrote :
description: updated
jazzynico (jazzynico) on 2016-01-27
Changed in inkscape:
assignee: nobody → jazzynico (jazzynico)
importance: Undecided → Medium
status: New → Triaged
jazzynico (jazzynico) wrote :

Fixed in the trunk, rev. 14918.

I have removed the inkex.localize() call from the extensions, but the change won't break custom extensions that still use it (it can be called several times with no issue).

Thanks for your suggestion, ~suv. Not only it solves the issue, but the extensions are a bit cleaner and easier to maintain. I'm still wondering why I didn't implement it from the beginning ;)

Changed in inkscape:
status: Triaged → Fix Committed
Bryce Harrington (bryce) on 2017-01-10
Changed in inkscape:
status: Fix Committed → Fix Released
su_v (suv-lp) wrote :

jazzynico wrote:
> I'm still wondering why I didn't implement it from the beginning

Maybe because of use cases like the issue 1 here:
 https://bugs.launchpad.net/inkscape/+bug/1664554/comments/11
(inkex.errormsg() with content to be translated is used in the initialization of an extension's inkex.Effect subclass, before affect() is run)

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers