From 001487ea1099b8f734d0f1dce7d5d13cf4e1e6ae Mon Sep 17 00:00:00 2001 From: pjrm Date: Fri, 23 May 2008 12:49:19 +0000 Subject: [PATCH] share/extensions/*.py: Use gettext for (many) error messages. share/extensions/inkex.py: (errormsg): New function. --- ChangeLog | 5 +++++ share/extensions/dimension.py | 2 +- share/extensions/embedimage.py | 8 ++++--- share/extensions/export_gimp_palette.py | 4 ++-- share/extensions/extractimage.py | 4 +++- share/extensions/inkex.py | 23 ++++++++++++++++++-- share/extensions/markers_strokepaint.py | 6 +++-- share/extensions/pathalongpath.py | 5 +++-- share/extensions/pathmodifier.py | 4 +++- share/extensions/pathscatter.py | 8 +++---- share/extensions/perspective.py | 11 +++++++--- share/extensions/polyhedron_3d.py | 4 +++- share/extensions/summersnight.py | 10 ++++++--- share/extensions/svg_and_media_zip_output.py | 4 +++- 14 files changed, 72 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 35bee2e1f..1e53daa2f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-05-23 Peter Moulder + + * share/extensions/*.py: Use gettext for (many) error messages. + share/extensions/inkex.py: (errormsg): New function. + 2007-06-24 Joel Holdsworth * modified the windows RC files to add version info and manifest data diff --git a/share/extensions/dimension.py b/share/extensions/dimension.py index f7dfb902e..4ff7148ef 100644 --- a/share/extensions/dimension.py +++ b/share/extensions/dimension.py @@ -94,7 +94,7 @@ class Dimension(pathmodifier.PathModifier): try: testing_the_water = self.bbox[0] except TypeError: - sys.exit('Unable to process this object. Try changing it into a path first.') + sys.exit(_('Unable to process this object. Try changing it into a path first.')) layer = self.current_layer diff --git a/share/extensions/embedimage.py b/share/extensions/embedimage.py index 01cefacb0..059bc063e 100644 --- a/share/extensions/embedimage.py +++ b/share/extensions/embedimage.py @@ -18,6 +18,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ''' import inkex, os, base64 +import gettext +_ = gettext.gettext class Embedder(inkex.Effect): def __init__(self): @@ -74,7 +76,7 @@ class Embedder(inkex.Effect): if (absref != None): path=absref if (not os.path.isfile(path)): - inkex.debug('No xlink:href or sodipodi:absref attributes found, or they do not point to an existing file! Unable to embed image.') + inkex.errormsg(_('No xlink:href or sodipodi:absref attributes found, or they do not point to an existing file! Unable to embed image.')) if (os.path.isfile(path)): file = open(path,"rb").read() @@ -97,9 +99,9 @@ class Embedder(inkex.Effect): if (absref != None): del node.attrib[inkex.addNS('absref',u'sodipodi')] else: - inkex.debug("%s is not of type image/png, image/jpeg, image/bmp, image/gif or image/x-icon" % path) + inkex.errormsg(_("%s is not of type image/png, image/jpeg, image/bmp, image/gif or image/x-icon") % path) else: - inkex.debug("Sorry we could not locate %s" % path) + inkex.errormsg(_("Sorry we could not locate %s") % path) if __name__ == '__main__': e = Embedder() diff --git a/share/extensions/export_gimp_palette.py b/share/extensions/export_gimp_palette.py index 31dad4552..1248a56bb 100644 --- a/share/extensions/export_gimp_palette.py +++ b/share/extensions/export_gimp_palette.py @@ -11,7 +11,7 @@ import sys, simplestyle try: from xml.dom.minidom import parse except: - sys.exit('The export_gpl.py module requires PyXML. Please download the latest version from .') + sys.exit(_('The export_gpl.py module requires PyXML. Please download the latest version from .')) colortags=(u'fill',u'stroke',u'stop-color',u'flood-color',u'lighting-color') colors={} @@ -47,4 +47,4 @@ for k,v in sorted(colors.items()): print k+v -# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99 +# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 diff --git a/share/extensions/extractimage.py b/share/extensions/extractimage.py index 07074c8a4..38f929846 100644 --- a/share/extensions/extractimage.py +++ b/share/extensions/extractimage.py @@ -18,6 +18,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ''' import inkex, base64, os +import gettext +_ = gettext.gettext class MyEffect(inkex.Effect): def __init__(self): @@ -61,7 +63,7 @@ class MyEffect(inkex.Effect): open(path,'wb').write(data) node.set(inkex.addNS('href','xlink'),os.path.realpath(path)) #absolute for making in-mem cycles work else: - inkex.debug('Difficulty finding the image data.') + inkex.errormsg(_('Difficulty finding the image data.')) break if __name__ == '__main__': diff --git a/share/extensions/inkex.py b/share/extensions/inkex.py index 5aa8912a9..b4872368e 100755 --- a/share/extensions/inkex.py +++ b/share/extensions/inkex.py @@ -20,6 +20,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ import sys, copy, optparse, random, re +import gettext +_ = gettext.gettext #a dictionary of all of the xmlns prefixes in a standard inkscape doc NSS = { @@ -56,12 +58,29 @@ def unittouu(string): try: from lxml import etree except: - sys.exit('The fantastic lxml wrapper for libxml2 is required by inkex.py and therefore this extension. Please download and install the latest version from , or install it through your package manager by a command like: sudo apt-get install python-lxml') + sys.exit(_('The fantastic lxml wrapper for libxml2 is required by inkex.py and therefore this extension. Please download and install the latest version from , or install it through your package manager by a command like: sudo apt-get install python-lxml')) def debug(what): sys.stderr.write(str(what) + "\n") return what +def errormsg(msg): + """Intended for end-user-visible error messages. + + (Currently just writes to stderr with an appended newline, but could do + something better in future: e.g. could add markup to distinguish error + messages from status messages or debugging output.) + + Note that this should always be combined with translation: + + import gettext + _ = gettext.gettext + ... + inkex.errormsg(_("This extension requires two selected paths.")) + """ + sys.stderr.write(str(msg) + "\n") + return what + def check_inkbool(option, opt, value): if str(value).capitalize() == 'True': return True @@ -165,7 +184,7 @@ class Effect: try: retval = self.document.xpath(path, namespaces=NSS)[0] except: - debug("No matching node for expression: %s" % path) + errormsg(_("No matching node for expression: %s") % path) retval = None return retval diff --git a/share/extensions/markers_strokepaint.py b/share/extensions/markers_strokepaint.py index 11fa77d0f..7408b08d6 100644 --- a/share/extensions/markers_strokepaint.py +++ b/share/extensions/markers_strokepaint.py @@ -17,6 +17,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ''' import random, inkex, simplestyle, copy +import gettext +_ = gettext.gettext class MyEffect(inkex.Effect): def __init__(self): @@ -36,7 +38,7 @@ class MyEffect(inkex.Effect): try: style = simplestyle.parseStyle(node.get('style')) except: - inkex.debug("No style attribute found for id: %s" % id) + inkex.errormsg(_("No style attribute found for id: %s") % id) continue stroke = style.get('stroke', '#000000') @@ -51,7 +53,7 @@ class MyEffect(inkex.Effect): else: mnode = old_mnode except: - inkex.debug("unable to locate marker: %s" % marker_id) + inkex.errormsg(_("unable to locate marker: %s") % marker_id) continue new_id = self.uniqueId(marker_id, not self.options.modify) diff --git a/share/extensions/pathalongpath.py b/share/extensions/pathalongpath.py index 917bc665b..f8a8a2c32 100644 --- a/share/extensions/pathalongpath.py +++ b/share/extensions/pathalongpath.py @@ -33,8 +33,9 @@ they move and rotate, deforming the pattern. import inkex, cubicsuperpath, bezmisc import pathmodifier,simpletransform - import copy, math, re, random +import gettext +_ = gettext.gettext def flipxy(path): for pathcomp in path: @@ -193,7 +194,7 @@ class PathAlongPath(pathmodifier.Diffeo): def effect(self): if len(self.options.ids)<2: - inkex.debug("This extension requires that you select two paths.") + inkex.errormsg(_("This extension requires two selected paths.")) return self.prepareSelectionList() self.options.wave = (self.options.kind=="Ribbon") diff --git a/share/extensions/pathmodifier.py b/share/extensions/pathmodifier.py index 645b7fb6c..e30ec5197 100644 --- a/share/extensions/pathmodifier.py +++ b/share/extensions/pathmodifier.py @@ -30,6 +30,8 @@ interest and that should be shipped out in separate files... import inkex, cubicsuperpath, bezmisc, simplestyle from simpletransform import * import copy, math, re, random +import gettext +_ = gettext.gettext #################################################################### ##-- zOrder computation... @@ -224,7 +226,7 @@ class PathModifier(inkex.Effect): newNode = self.unlinkClone(node,doReplace) return self.objectToPath(newNode,doReplace) else: - inkex.debug("Please first convert objects to paths!...(got '%s')"%node.tag) + inkex.errormsg(_("Please first convert objects to paths! (Got <%s>.)") % node.tag) return None def objectsToPaths(self,aList,doReplace=True): diff --git a/share/extensions/pathscatter.py b/share/extensions/pathscatter.py index 20623de6a..03da822c5 100644 --- a/share/extensions/pathscatter.py +++ b/share/extensions/pathscatter.py @@ -34,8 +34,9 @@ they move and rotate, deforming the pattern. import inkex, cubicsuperpath, bezmisc import pathmodifier, simpletransform from lxml import etree - import copy, math, re, random +import gettext +_ = gettext.gettext def zSort(inNode,idList): sortedList=[] @@ -204,7 +205,7 @@ class PathScatter(pathmodifier.Diffeo): def effect(self): if len(self.options.ids)<2: - inkex.debug("This extension requires that you select two paths.") + inkex.errormsg(_("This extension requires two selected paths.")) return self.prepareSelectionList() @@ -254,10 +255,9 @@ class PathScatter(pathmodifier.Diffeo): s+=dx self.patternNode.getparent().remove(self.patternNode) - if __name__ == '__main__': e = PathScatter() e.affect() - + # vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99 diff --git a/share/extensions/perspective.py b/share/extensions/perspective.py index 53b1a9149..6cd917e22 100755 --- a/share/extensions/perspective.py +++ b/share/extensions/perspective.py @@ -19,12 +19,14 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Perspective approach & math by Dmitry Platonov, shadowjack@mail.ru, 2006 """ import sys, inkex, os, re, simplepath, cubicsuperpath +import gettext +_ = gettext.gettext from ffgeom import * try: from numpy import * from numpy.linalg import * except: - inkex.debug("Failed to import the numpy or numpy.linalg modules. These modules are required by this extension. Please install them and try again. On a Debian-like system this can be done with the command, sudo apt-get install python-numpy.") + inkex.errormsg(_("Failed to import the numpy or numpy.linalg modules. These modules are required by this extension. Please install them and try again. On a Debian-like system this can be done with the command, sudo apt-get install python-numpy.")) sys.exit() uuconv = {'in':90.0, 'pt':1.25, 'px':1, 'mm':3.5433070866, 'cm':35.433070866, 'pc':15.0} @@ -50,7 +52,7 @@ class Project(inkex.Effect): inkex.Effect.__init__(self) def effect(self): if len(self.options.ids) < 2: - inkex.debug("Requires two selected paths. The second must be exactly four nodes long.") + inkex.errormsg(_("This extension requires two selected paths.")) sys.exit() #obj is selected second @@ -58,6 +60,9 @@ class Project(inkex.Effect): envelope = self.selected[self.options.ids[1]] if (obj.tag == inkex.addNS('path','svg') or obj.tag == inkex.addNS('g','svg')) and envelope.tag == inkex.addNS('path','svg'): path = cubicsuperpath.parsePath(envelope.get('d')) + if len(path) < 1 or len(path[0]) < 4: + inkex.errormsg(_("This extension requires that the second selected path be four nodes long.")) + sys.exit() dp = zeros((4,2), dtype=float64) for i in range(4): dp[i][0] = path[0][i][1][0] @@ -68,7 +73,7 @@ class Project(inkex.Effect): file = self.args[-1] id = self.options.ids[0] for query in q.keys(): - _,f,err = os.popen3('inkscape --query-%s --query-id=%s "%s"' % (query,id,file)) + f,err = os.popen3('inkscape --query-%s --query-id=%s "%s"' % (query,id,file))[1:] q[query] = float(f.read()) f.close() err.close() diff --git a/share/extensions/polyhedron_3d.py b/share/extensions/polyhedron_3d.py index 006d16d6b..fca66b113 100644 --- a/share/extensions/polyhedron_3d.py +++ b/share/extensions/polyhedron_3d.py @@ -52,10 +52,12 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import inkex import simplestyle, sys, simplepath, re from math import * +import gettext +_ = gettext.gettext try: from numpy import * except: - inkex.debug("Failed to import the numpy module. This module is required by this extension. Please install them and try again. On a Debian-like system this can be done with the command, sudo apt-get install python-numpy.") + inkex.errormsg(_("Failed to import the numpy module. This module is required by this extension. Please install them and try again. On a Debian-like system this can be done with the command, sudo apt-get install python-numpy.")) sys.exit() def objfile(name): diff --git a/share/extensions/summersnight.py b/share/extensions/summersnight.py index f3d9811c4..86da134b9 100755 --- a/share/extensions/summersnight.py +++ b/share/extensions/summersnight.py @@ -19,14 +19,18 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ import inkex, os, simplepath, cubicsuperpath from ffgeom import * +import gettext +_ = gettext.gettext class Project(inkex.Effect): def __init__(self): inkex.Effect.__init__(self) def effect(self): if len(self.options.ids) < 2: - inkex.debug("Requires two selected paths. The second must be exactly four nodes long.") - exit() + inkex.errormsg(_("This extension requires two selected paths.") + + " " + + _("The second path must be exactly four nodes long.")) + exit() #obj is selected second obj = self.selected[self.options.ids[0]] @@ -47,7 +51,7 @@ class Project(inkex.Effect): file = self.args[-1] id = self.options.ids[0] for query in self.q.keys(): - _,f,err = os.popen3('inkscape --query-%s --query-id=%s "%s"' % (query,id,file)) + f,err = os.popen3('inkscape --query-%s --query-id=%s "%s"' % (query,id,file))[1:] self.q[query] = float(f.read()) f.close() err.close() diff --git a/share/extensions/svg_and_media_zip_output.py b/share/extensions/svg_and_media_zip_output.py index 001d5b0f8..e34f01749 100644 --- a/share/extensions/svg_and_media_zip_output.py +++ b/share/extensions/svg_and_media_zip_output.py @@ -40,6 +40,8 @@ import zipfile import shutil import sys import tempfile +import gettext +_ = gettext.gettext class MyEffect(inkex.Effect): def __init__(self): @@ -98,7 +100,7 @@ class MyEffect(inkex.Effect): shutil.copy(tmp_dir + os.path.sep + absref,tmp_dir) z.write(tmp_dir + os.path.sep + absref.encode("latin-1"),os.path.basename(absref).encode("latin-1")) else: - inkex.debug('Could not locate file: %s' % absref) + inkex.errormsg(_('Could not locate file: %s') % absref) node.set(inkex.addNS('href',u'xlink'),os.path.basename(absref)) node.set(inkex.addNS('absref',u'sodipodi'),os.path.basename(absref)) -- 2.30.2