diff --git a/barcode/Base.py b/barcode/Base.py index f9b15c3c3facdfc4dd525101889e0e754eb37ac4..024213cb9000f20e8f2f64e96a6c53c7624e4e5b 100644 --- a/barcode/Base.py +++ b/barcode/Base.py @@ -24,6 +24,7 @@ import itertools import sys from inkex import Group, TextElement, Rectangle +from inkex.localization import inkex_gettext as _ (TEXT_POS_BOTTOM, TEXT_POS_TOP) = range(2) (WHITE_BAR, BLACK_BAR, TALL_BAR) = range(3) @@ -45,7 +46,7 @@ class Barcode(object): def error(self, text, msg): """Cause an error to be reported""" sys.stderr.write( - "Error encoding '{}' as {} barcode: {}\n".format(text, self.name, msg) + _("Error encoding '{}' as {} barcode: {}\n").format(text, self.name, msg) ) return "ERROR" @@ -73,7 +74,7 @@ class Barcode(object): self.known_ids = list(self.document.xpath("//@id")) if not self.text: - raise ValueError("No string specified for barcode.") + raise ValueError(_("No string specified for barcode.")) def get_id(self, name="element"): """Get the next useful id (and claim it)""" diff --git a/barcode/BaseEan.py b/barcode/BaseEan.py index e108b644e1c3d606d902b17be54c77309741e632..d1ab58e220ba86c2a6f7c3604e985e6c93dbe7a7 100644 --- a/barcode/BaseEan.py +++ b/barcode/BaseEan.py @@ -21,6 +21,7 @@ Some basic common code shared between EAN and UCP generators. """ from .Base import Barcode, TEXT_POS_TOP +from inkex.localization import inkex_gettext as _ try: from typing import Optional, List, Dict @@ -138,7 +139,7 @@ class EanBarcode(Barcode): code = code.strip(">") if not code.isdigit(): - return self.error(code, "Not a Number, must be digits 0-9 only") + return self.error(code, _("Not a Number, must be digits 0-9 only")) lengths = self.get_lengths() + self.checks # Allow extra barcodes after the first one @@ -158,7 +159,7 @@ class EanBarcode(Barcode): if len(code) not in lengths: return self.error( code, - "Wrong size {:d}, must be {} digits".format( + _("Wrong size {:d}, must be {} digits").format( len(code), ", ".join([str(length) for length in lengths]) ), ) @@ -167,7 +168,7 @@ class EanBarcode(Barcode): if len(code) not in self.checks: code = self.append_checksum(code) elif not self.verify_checksum(code): - return self.error(code, "Checksum failed, omit for new sum") + return self.error(code, _("Checksum failed, omit for new sum")) return self._encode(EanBarcode.intarray(code), guide=guide) def _encode(self, num, guide=False): diff --git a/barcode/Code25i.py b/barcode/Code25i.py index c7e520399eb395880c6499ac0ff2340cef90aeb7..adc0161017b879483c025461fd35e6b3e625023d 100644 --- a/barcode/Code25i.py +++ b/barcode/Code25i.py @@ -21,6 +21,7 @@ Generate barcodes for Code25-interleaved 2 of 5, for Inkscape. """ from .Base import Barcode +from inkex.localization import inkex_gettext as _ # 1 means thick, 0 means thin ENCODE = { @@ -43,7 +44,7 @@ class Code25i(Barcode): # Start and stop code are already encoded into white (0) and black(1) bars def encode(self, text): if not text.isdigit(): - return self.error(text, "CODE25 can only encode numbers.") + return self.error(text, _("CODE25 can only encode numbers.")) number = text # Number of figures to encode must be even, diff --git a/barcode/Upce.py b/barcode/Upce.py index d92e5a2038cd29548eb5537f57d4e476b2b9aaea..9404ca2cc6617cc856a98688b1c667ceee79df03 100644 --- a/barcode/Upce.py +++ b/barcode/Upce.py @@ -21,6 +21,7 @@ Python barcode renderer for UPCE barcodes. Designed for use with Inkscape. """ from .BaseEan import EanBarcode +from inkex.localization import inkex_gettext as _ # This is almost exactly the same as the standard FAMILIES # But flipped around and with the first 111000 instead of 000000. @@ -66,7 +67,7 @@ class Upce(EanBarcode): # All UPC-E Numbers use number system 0 if number[0] != "0" or len(number) != 11: # If not then the code is invalid - raise ValueError("Invalid UPC Number") + raise ValueError(_("Invalid UPC Number")) # Most of the conversions deal # with the specific code parts @@ -92,7 +93,7 @@ class Upce(EanBarcode): # the 0-4 used above. return maker + product[4] # Invalid UPC-A Numbe - raise ValueError("Invalid UPC Number") + raise ValueError(_("Invalid UPC Number")) @staticmethod def convert_e2a(number): diff --git a/barcode/__init__.py b/barcode/__init__.py index acc7a4a85903933f91af8041061ffe8514869b00..1bfe281ef27c56ffa76e176a3ec765c01adcab5b 100644 --- a/barcode/__init__.py +++ b/barcode/__init__.py @@ -23,6 +23,7 @@ Renderer for barcodes, SVG extension for Inkscape. For supported barcodes see Barcode module directory. """ +from inkex.localization import inkex_gettext as _ # This lists all known Barcodes missing from this package # ===== UPC-Based Extensions ====== # @@ -49,7 +50,7 @@ class NoBarcode: def encode(self, text): """Encode the text into a barcode pattern""" - raise ValueError("No barcode encoder: {}".format(self.msg)) + raise ValueError(_("No barcode encoder: {}").format(self.msg)) def generate(self): """Generate actual svg from the barcode pattern""" @@ -59,7 +60,7 @@ class NoBarcode: def get_barcode(code, **kw): """Gets a barcode from a list of available barcode formats""" if not code: - return NoBarcode("No barcode format given.") + return NoBarcode(_("No barcode format given.")) code = str(code).replace("-", "").strip() module = "barcode." + code @@ -68,9 +69,9 @@ def get_barcode(code, **kw): return getattr(__import__(module, fromlist=lst), code)(kw) except ImportError as err: if code in str(err): - return NoBarcode("Invalid type of barcode: {}.{}".format(module, code)) + return NoBarcode(_("Invalid type of barcode: {}.{}").format(module, code)) raise except AttributeError: return NoBarcode( - "Barcode module is missing barcode class: {}.{}".format(module, code) + _("Barcode module is missing barcode class: {}.{}").format(module, code) ) diff --git a/color_randomize.py b/color_randomize.py index b17c99c0709846a0189106b7157fafac8e5fb22e..e25dc6d3e8d0f3d714a2bbf3791cab0295f8d355 100755 --- a/color_randomize.py +++ b/color_randomize.py @@ -3,6 +3,7 @@ from random import randrange, uniform, seed import inkex +from inkex.localization import inkex_gettext as _ def _rand( @@ -76,7 +77,7 @@ class Randomize(inkex.ColorExtension): try: opacity = float(opacity) except ValueError: - self.msg(f"Ignoring unusual opacity value: {opacity}") + self.msg(_("Ignoring unusual opacity value: {}").format(opacity)) return opacity orange = self.options.opacity_range if orange > 0: diff --git a/convert2dashes.py b/convert2dashes.py index 2908e4924853fd9fa5e540fd71d34c96037141fa..2fecdccfaba1b91aebd7e0b4299dc9f6ea6f9431 100755 --- a/convert2dashes.py +++ b/convert2dashes.py @@ -24,6 +24,7 @@ It is a modification of the file addnodes.py """ import inkex from inkex import bezier, CubicSuperPath, Group, PathElement +from inkex.localization import inkex_gettext as _ class Dashit(inkex.EffectExtension): diff --git a/dhw_input.py b/dhw_input.py index f5cca723d36e0a65e1a4d40ca2c98a30a4a2edcf..80349c786074a7f79e6e2765a05c0ab5481105e4 100755 --- a/dhw_input.py +++ b/dhw_input.py @@ -28,6 +28,7 @@ import struct import inkex from inkex import AbortExtension, errormsg, Group, Polyline +from inkex.localization import inkex_gettext as _ inkex.NSS["dm"] = "http://github.com/nikitakit/DM2SVG" @@ -59,7 +60,7 @@ class DhwInput(inkex.InputExtension): header = list(struct.unpack("<32sBHHBxx", stream.read(40))) doc = header.pop(0).decode() if doc != "ACECAD_DIGIMEMO_HANDWRITING_____": - raise AbortExtension("Could not load file, not a ACECAD DHW file!") + raise AbortExtension(_("Could not load file, not a ACECAD DHW file!")) height = int(header[2]) doc = self.get_template(**dict(zip(("v", "w", "h", "p"), header))) @@ -74,7 +75,7 @@ class DhwInput(inkex.InputExtension): break if ord(tag) <= 128: - errormsg("Unsupported tag: {}\n".format(tag)) + errormsg(_("Unsupported tag: {}\n").format(tag)) continue if tag == b"\x90": diff --git a/dimension.py b/dimension.py index bde92b9ffafc560345f8e09cc5d194da5f67e21c..b452b8211ffe3a2f36f5396533350da651387aba 100755 --- a/dimension.py +++ b/dimension.py @@ -35,6 +35,7 @@ extensions library, and marker data from markers.svg. import inkex from inkex import Group, Marker, PathElement +from inkex.localization import inkex_gettext as _ import pathmodifier @@ -103,7 +104,7 @@ class Dimension(pathmodifier.PathModifier): self.options.yoffset *= scale if not self.svg.selection: - raise inkex.AbortExtension("Please select an object") + raise inkex.AbortExtension(_("Please select an object")) if self.options.type == "geometric": bbox = self.svg.selection.bounding_box() else: diff --git a/docinfo.py b/docinfo.py index 88535b75bf5885f8f076582d0a62bcff8c952250..dd477a0e54d521637ac9fe24c29114b940ef39f9 100755 --- a/docinfo.py +++ b/docinfo.py @@ -22,35 +22,39 @@ import inkex +from inkex.localization import inkex_gettext as _ + class DocInfo(inkex.EffectExtension): """Show document information""" def effect(self): namedview = self.svg.namedview - self.msg(":::SVG document related info:::") + self.msg(_(":::SVG document related info:::")) self.msg( - "version: " + self.svg.get("inkscape:version", "New Document (unsaved)") + _("version: {}").format( + self.svg.get("inkscape:version", _("New Document (unsaved)")) + ) ) - self.msg("width: {}".format(self.svg.viewport_width)) - self.msg("height: {}".format(self.svg.viewport_height)) - self.msg("viewbox: {}".format(str(self.svg.get_viewbox()))) + self.msg(_("width: {}").format(self.svg.viewport_width)) + self.msg(_("height: {}").format(self.svg.viewport_height)) + self.msg(_("viewbox: {}").format(str(self.svg.get_viewbox()))) self.msg( - "document-units: {}".format( + _("document-units: {}").format( namedview.get("inkscape:document-units", "None") ) ) - self.msg("units: " + namedview.get("units", "None")) - self.msg("Document has " + str(len(namedview.get_guides())) + " guides") + self.msg(_("units: ") + namedview.get("units", "None")) + self.msg(_("Document has {} guides").format(len(namedview.get_guides()))) for i, grid in enumerate(namedview.findall("inkscape:grid")): self.msg( - "Grid number {}: Units: {}".format(i + 1, grid.get("units", "None")) + _("Grid number {}: Units: {}").format(i + 1, grid.get("units", "None")) ) if len(namedview.get_pages()) > 1: - self.msg("Document has " + str(len(namedview.get_pages())) + " pages") + self.msg(_("Document has {} pages").format(len(namedview.get_pages()))) for i, page in enumerate(namedview.get_pages()): self.msg( - "Page number {}: x: {} y: {} width: {} height: {}".format( + _("Page number {}: x: {} y: {} width: {} height: {}").format( i + 1, page.get("x"), page.get("y"), @@ -59,7 +63,7 @@ class DocInfo(inkex.EffectExtension): ) ) else: - self.msg("This is a single page document.") + self.msg(_("This is a single page document.")) if __name__ == "__main__": diff --git a/dxf_input.py b/dxf_input.py index d614e45a77ebe59ccc1691dfae5427b6900b09e0..9b6a4e3a58fbfa37b50c7e68d73814e70701f06d 100644 --- a/dxf_input.py +++ b/dxf_input.py @@ -33,6 +33,7 @@ from urllib.parse import quote from lxml import etree import inkex +from inkex.localization import inkex_gettext as _ global defs global block # 2021.6 @@ -1252,7 +1253,10 @@ class DxfInput(inkex.InputExtension): if line[0] == "AutoCAD Binary DXF": inkex.errormsg( - "Inkscape cannot read binary DXF files. \nPlease convert to ASCII format first." + _( + "Inkscape cannot read binary DXF files. \n" + "Please convert to ASCII format first." + ) + str(len(line[0])) + " " + str(len(line[1])) diff --git a/dxf_outlines.py b/dxf_outlines.py index 4c61a4dfdd607260f1ecd50c67f5e44761b4a91a..de05289a459b6244a04f619a8a9fa83d18a42b13 100755 --- a/dxf_outlines.py +++ b/dxf_outlines.py @@ -49,6 +49,7 @@ from inkex import ( Circle, Ellipse, ) +from inkex.localization import inkex_gettext as _ def get_matrix(u, i, j): @@ -208,7 +209,11 @@ class DxfOutlines(inkex.OutputExtension): from numpy.linalg import solve except ImportError: inkex.errormsg( - "Failed to import the numpy or numpy.linalg modules. These modules are required by the ROBO option. Please install them and try again." + _( + "Failed to import the numpy or numpy.linalg modules. " + "These modules are required by the ROBO option." + "Please install them and try again." + ) ) return @@ -353,7 +358,10 @@ class DxfOutlines(inkex.OutputExtension): and not self.options.layer_name ): return inkex.errormsg( - "Error: Field 'Layer match name' must be filled when using 'By name match' option" + _( + "Error: Field 'Layer match name' must be filled when using " + "'By name match' option" + ) ) # Split user layer data into a list: "layerA,layerb,LAYERC" becomes ["layera", "layerb", "layerc"] @@ -420,7 +428,7 @@ class DxfOutlines(inkex.OutputExtension): ): for layer in self.options.layer_name: if layer not in self.layernames: - inkex.errormsg("Warning: Layer '%s' not found!" % layer) + inkex.errormsg(_("Warning: Layer '{}' not found!").format(layer)) if __name__ == "__main__": diff --git a/extension-manager-bootstrap.py b/extension-manager-bootstrap.py index 6b38d2bf891842a71c62d7ec96ea2d27a980239e..e634bbe785e70ff282571d14d96e47a17485156d 100644 --- a/extension-manager-bootstrap.py +++ b/extension-manager-bootstrap.py @@ -29,6 +29,7 @@ import inkex from inkex.utils import get_user_directory from inkex.base import InkscapeExtension from inkex.command import CommandNotFound, ProgramRunError, call +from inkex.localization import inkex_gettext as _ TARGET_DIR = get_user_directory() FALLBACK_DIR = os.path.join(TARGET_DIR or "./", "org.inkscape.inkman") @@ -61,7 +62,7 @@ class Bootstrap(InkscapeExtension): try: from manage_extensions import run as run_existing except (ImportError, ModuleNotFoundError): - return self.msg("Extension manager installed, please re-run.") + return self.msg(_("Extension manager installed, please re-run.")) run_existing(sys.argv) def effect(self): @@ -72,7 +73,8 @@ class Bootstrap(InkscapeExtension): fallback = True except ProgramRunError as err: raise inkex.AbortExtension( - "There has been a problem creating the python environment:\n" + str(err) + _("There has been a problem creating the python environment:\n") + + str(err) ) if fallback: @@ -80,9 +82,12 @@ class Bootstrap(InkscapeExtension): if self.install_fallback(): return raise inkex.AbortExtension( - "You must have the python-virtualenv package installed. This should have" - " been included with Inkscape, but in some special cases it might not" - " be. Please install this software externally and try again." + _( + "You must have the python-virtualenv package installed. This " + "should have been included with Inkscape, but in some special " + "cases it might not be. Please install this software externally " + "and try again." + ) ) try: @@ -91,11 +96,11 @@ class Bootstrap(InkscapeExtension): ) except CommandNotFound: raise inkex.AbortExtension( - "Can't find pip program after environment initialisation!" + _("Can't find pip program after environment initialisation!") ) except ProgramRunError as err: raise inkex.AbortExtension( - "Error installing extension manager package:\n" + str(err) + _("Error installing extension manager package:\n") + str(err) ) def install_fallback(self): @@ -121,7 +126,9 @@ class Bootstrap(InkscapeExtension): ) except NewConnectionError: self.msg( - "Could not connect to the internet, please check connection and try again!" + _( + "Could not connect to the internet, please check connection and try again!" + ) ) finally: session.close() diff --git a/funcplot.py b/funcplot.py index 9e67222afe51233118c5152857d03875e95d28ac..78a712ca0cae07250a459369610470663fb0417a 100755 --- a/funcplot.py +++ b/funcplot.py @@ -31,6 +31,8 @@ import inkex from inkex import ClipPath, Rectangle from inkex.utils import math_eval +from inkex.localization import inkex_gettext as _ + def drawfunction( xstart, @@ -58,7 +60,10 @@ def drawfunction( # coords and scales based on the source rect if xstart == xend: inkex.errormsg( - "x-interval cannot be zero. Please modify 'Start X value' or 'End X value'" + _( + "x-interval cannot be zero. Please modify 'Start X value' " + "or 'End X value'" + ) ) return [] scalex = width / (xend - xstart) @@ -72,7 +77,10 @@ def drawfunction( if ytop == ybottom: inkex.errormsg( - "y-interval cannot be zero. Please modify 'Y value of rectangle's top' or 'Y value of rectangle's bottom'" + _( + "y-interval cannot be zero. Please modify 'Y value of rectangle's top' " + "or 'Y value of rectangle's bottom'" + ) ) return [] scaley = height / (ytop - ybottom) diff --git a/guillotine.py b/guillotine.py index abc9f933636ead7f9cf851837c7fbd70c08bda71..6450633914657b5dc96bbce59dce187b5ed7c929 100755 --- a/guillotine.py +++ b/guillotine.py @@ -41,6 +41,7 @@ import locale import inkex from inkex.command import inkscape +from inkex.localization import inkex_gettext as _ class Guillotine(inkex.EffectExtension): @@ -125,7 +126,7 @@ class Guillotine(inkex.EffectExtension): if not self.options.ignore: if self.options.image == "" or self.options.image is None: - raise inkex.AbortExtension("Please enter an image name") + raise inkex.AbortExtension(_("Please enter an image name")) return self.options.directory, self.options.image else: """ @@ -139,9 +140,11 @@ class Guillotine(inkex.EffectExtension): export_file = self.svg.get("inkscape:export-filename") except KeyError: raise inkex.AbortExtension( - "To use the export hints option, you " - "need to have previously exported the document. " - "Otherwise no export hints exist!" + _( + "To use the export hints option, you " + "need to have previously exported the document. " + "Otherwise no export hints exist!" + ) ) dirname, filename = os.path.split(export_file) filename = filename.rsplit(".", 1)[0] # Without extension @@ -185,7 +188,7 @@ class Guillotine(inkex.EffectExtension): self.export_slice(slico, fname) self.debug( - "The sliced bitmaps have been saved as:" + "\n\n" + "\n".join(output_files) + _("The sliced bitmaps have been saved as:\n\n") + "\n".join(output_files) ) def effect(self): diff --git a/hershey.py b/hershey.py index b532e0dd8f32435c110e731b90296da8887c570c..e2586c2154a6ed9c9dec1e9c8e9688ad278287b5 100644 --- a/hershey.py +++ b/hershey.py @@ -56,6 +56,7 @@ from copy import deepcopy import inkex from inkex import Transform, Style, units, AbortExtension +from inkex.localization import inkex_gettext as _ from inkex import ( load_svg, @@ -381,7 +382,7 @@ Evil Mad Scientist Laboratories if doc_width is None or doc_height is None: raise AbortExtension( - "Width or height attribute missing on toplevel tag" + _("Width or height attribute missing on toplevel tag") ) d_width = float(doc_width) @@ -727,7 +728,7 @@ Evil Mad Scientist Laboratories except IOError: self.font_dict[fontname] = None except: - inkex.errormsg("Error parsing SVG font at " + str(the_path)) + inkex.errormsg(_("Error parsing SVG font at {}").format(str(the_path))) self.font_dict[fontname] = None def font_table(self): @@ -800,7 +801,7 @@ Evil Mad Scientist Laboratories fontname = self.font_load_wrapper("not_a_font_name") # force load of default if self.font_load_fail: - inkex.errormsg("Font not found; Unable to generate glyph table.") + inkex.errormsg(_("Font not found; Unable to generate glyph table.")) return # Embed in group to make manipulation easier: @@ -1379,7 +1380,7 @@ Evil Mad Scientist Laboratories ref_group = anode_list.add(Group()) # Add a subgroup except AttributeError: inkex.errormsg( - "Unable to process text. Consider unlinking cloned text." + _("Unable to process text. Consider unlinking cloned text.") ) continue @@ -2010,14 +2011,16 @@ Evil Mad Scientist Laboratories parent.remove(element_to_remove) if self.font_load_fail: - inkex.errormsg("Warning: unable to load SVG stroke fonts.") + inkex.errormsg(_("Warning: unable to load SVG stroke fonts.")) if self.warn_unflow: inkex.errormsg( - "Warning: unable to convert text flowed into a frame.\n" - + "Please use Text > Unflow to convert it prior to use.\n" - + "If you are unable to identify the object in question, " - + "please contact technical support for help." + _( + "Warning: unable to convert text flowed into a frame.\n" + + "Please use Text > Unflow to convert it prior to use.\n" + + "If you are unable to identify the object in question, " + + "please contact technical support for help." + ) ) diff --git a/hpgl_input.py b/hpgl_input.py index 538ff73916193bcc2e1659d826d001a992fd3752..0c998d695a96f513a408ba2134988b1dfdd103ac 100755 --- a/hpgl_input.py +++ b/hpgl_input.py @@ -63,7 +63,8 @@ class HpglInput(inkex.InputExtension): if "UNKNOWN_COMMANDS" in warnings: inkex.errormsg( _( - "The HPGL data contained unknown (unsupported) commands, there is a possibility that the drawing is missing some content." + "The HPGL data contained unknown (unsupported) commands, " + "there is a possibility that the drawing is missing some content." ) ) diff --git a/image_extract.py b/image_extract.py index bb282ca94ce2e26b68aea17a8c4518ad798ff705..39132cdbe161de9a2bedbbff4312c876399e396e 100755 --- a/image_extract.py +++ b/image_extract.py @@ -24,6 +24,7 @@ Extract embedded images. import os import inkex from inkex import Image +from inkex.localization import inkex_gettext as _ try: from base64 import decodebytes @@ -86,11 +87,11 @@ class ExtractImage(inkex.EffectExtension): (mimetype, data) = data.split(";", 1) (base, data) = data.split(",", 1) except ValueError: - inkex.errormsg("Invalid image format found") + inkex.errormsg(_("Invalid image format found")) return if base != "base64": - inkex.errormsg("Can't decode encoding: {}".format(base)) + inkex.errormsg(_("Can't decode encoding: {}").format(base)) return file_ext = self.mime_to_ext(mimetype) @@ -98,11 +99,11 @@ class ExtractImage(inkex.EffectExtension): pathwext = os.path.join(save_to, node.get("id") + file_ext) if os.path.isfile(pathwext): inkex.errormsg( - "Can't extract image, filename already used: {}".format(pathwext) + _("Can't extract image, filename already used: {}").format(pathwext) ) return - self.msg("Image extracted to: {}".format(pathwext)) + self.msg(_("Image extracted to: {}").format(pathwext)) with open(pathwext, "wb") as fhl: fhl.write(decodebytes(data.encode("utf-8"))) diff --git a/ink2canvas_lib/svg.py b/ink2canvas_lib/svg.py index 86c7bc452280c01d84e9e5d0ab77393966441861..fc09e50933a07e5ebf43e721800aac2ca0292c58 100644 --- a/ink2canvas_lib/svg.py +++ b/ink2canvas_lib/svg.py @@ -24,6 +24,7 @@ from __future__ import unicode_literals import math import inkex +from inkex.localization import inkex_gettext as _ # pylint: disable=missing-function-docstring, missing-class-docstring @@ -310,7 +311,7 @@ class Text(AbstractShape): def draw(self): for tspan in self.node: if isinstance(tspan, inkex.TextPath): - raise ValueError("TextPath elements are not supported") + raise ValueError(_("TextPath elements are not supported")) style = self.get_style() if self.has_transform(): trans_matrix = self.get_transform() diff --git a/interp_att_g.py b/interp_att_g.py index 0e3674aa3b021a2b9d72a7b30a9c08c5789a9749..61b8d8b715f9a0bc5ba0b1d9847e4d9bf8c39f6c 100755 --- a/interp_att_g.py +++ b/interp_att_g.py @@ -136,7 +136,9 @@ class InterpAttG(inkex.EffectExtension): node.style[att_name] = value elif path.startswith("transform/"): if not is_number(value): - raise inkex.AbortExtension(f"Unable to set attribute {path} to {value}") + raise inkex.AbortExtension( + _("Unable to set attribute {} to {}").format(path, value) + ) if path == "transform/trans-x": node.transform.add_translate(value, 0) elif path == "transform/trans-y": diff --git a/jessyink_summary.py b/jessyink_summary.py index 37eaba118330cf021cad365fe2f7d2ad4af8a016..698abbfdf95bb33374ee52f8a707b4d54cd00e42 100755 --- a/jessyink_summary.py +++ b/jessyink_summary.py @@ -36,7 +36,7 @@ class Summary(JessyInkMixin, inkex.EffectExtension): for node in self.svg.xpath("//svg:script[@id='JessyInk']"): version = node.get("jessyink:version") if version: - self.msg(_(f"JessyInk script version {version} installed.")) + self.msg(_("JessyInk script version {} installed.".format(version))) else: self.msg(_("JessyInk script installed.")) @@ -77,7 +77,13 @@ class Summary(JessyInkMixin, inkex.EffectExtension): name = trans["name"] if name != "appear" and "length" in trans: length = int(trans["length"] / 1000.0) - self.msg(_(f"{prefix}Transition {transition}: {name} ({length!s} s)")) + self.msg( + _( + "{0}Transition {1}: {2} ({3!s} s)".format( + prefix, transition, name, length + ) + ) + ) else: self.msg(_(f"{prefix}Transition {transition}: {name}")) @@ -86,13 +92,15 @@ class Summary(JessyInkMixin, inkex.EffectExtension): auto_texts = {"slide_num": dat[0], "num": dat[1], "title": dat[2]} for x, child in enumerate(node.xpath(".//*[@jessyink:autoText]")): if not x: - self.msg(_(f"\n{prefix}Auto-texts:")) + self.msg(_("\n{0}Auto-texts:").format(prefix)) pid = child.getparent().get("id") val = auto_texts[child.get("jessyink:autoText")] self.msg( _( - f'{prefix}\t"{child.text}" (object id "{pid}") will be replaced by "{val}".' + _('{0}\t"{1}" (object id "{2}") will be replaced by "{3}".').format( + prefix, child.text, pid, val + ) ) ) @@ -104,16 +112,22 @@ class Summary(JessyInkMixin, inkex.EffectExtension): order = effect[0]["order"] if not x: - ret += _(f"\n{prefix}Initial effect (order number {order}):") + ret += _("\n{0}Initial effect (order number {1}):").format( + prefix, order + ) else: - ret += _(f"\n{prefix}Effect {enum!s} (order number {order}):") + ret += _("\n{0}Effect {1} (order number {2}):").format( + prefix, enum, order + ) for item in effect: eid = item["id"] if item["type"] == "view": - ret += _(f'{prefix}\tView will be set according to object "{eid}"') + ret += _('{0}\tView will be set according to object "{1}"').format( + prefix, eid + ) else: - ret += _(f'{prefix}\tObject "{eid}"') + ret += _('{0}\tObject "{1}"').format(prefix, eid) if item["direction"] == "in": ret += _(" will appear") diff --git a/jessyink_transitions.py b/jessyink_transitions.py index 356a2046a788af8c4eef42f22182985011cd6036..3ddc1d3e83377c298f60d2971d6154c398c10f06 100755 --- a/jessyink_transitions.py +++ b/jessyink_transitions.py @@ -46,7 +46,7 @@ class Transitions(JessyInkMixin, inkex.EffectExtension): ) if node is None: raise inkex.AbortExtension( - _(f"Layer '{self.options.layerName}' not found.") + _("Layer '{}' not found.").format(self.options.layerName) ) if self.options.effectIn == "default": diff --git a/layer2png.py b/layer2png.py index 1f3e3c9b5ec5ea957ee2b8aab5ed84f49f750b0e..57146be1a021f2c0e28bee89dcf48ab22a70c5b8 100755 --- a/layer2png.py +++ b/layer2png.py @@ -53,6 +53,7 @@ import tempfile import inkex from inkex.command import inkscape +from inkex.localization import inkex_gettext as _ class ExportSlices(inkex.EffectExtension): @@ -94,7 +95,7 @@ class ExportSlices(inkex.EffectExtension): nodes = self.get_layer_nodes(self.options.layer) if nodes is None: raise inkex.AbortExtension( - "Slice: '{}' does not exist.".format(self.options.layer) + _("Slice: '{}' does not exist.").format(self.options.layer) ) # set opacity to zero in slices @@ -104,7 +105,7 @@ class ExportSlices(inkex.EffectExtension): # save file once now # if we have multiple slices we will make multiple calls # to inkscape - (_, tmp_svg) = tempfile.mkstemp(".svg") + (__, tmp_svg) = tempfile.mkstemp(".svg") with open(tmp_svg, "wb") as fout: fout.write(self.svg.tostring()) @@ -191,7 +192,7 @@ class ExportSlices(inkex.EffectExtension): kwargs["export-width"] = str(width) return color, kwargs else: - inkex.errormsg("Export exists ({}) not overwriting".format(filename)) + inkex.errormsg(_("Export exists ({}), not overwriting").format(filename)) return color, {} diff --git a/layout_nup.py b/layout_nup.py index f20e2c71421c013ae5f107744b62e82b9bb59b30..db7a5441683c545df78447611095a5e7646aba0f 100755 --- a/layout_nup.py +++ b/layout_nup.py @@ -22,6 +22,7 @@ from __future__ import absolute_import, unicode_literals import inkex from inkex import Use, Rectangle from inkex.base import SvgOutputMixin +from inkex.localization import inkex_gettext as _ class Nup(inkex.OutputExtension, SvgOutputMixin): @@ -159,7 +160,7 @@ class Nup(inkex.OutputExtension, SvgOutputMixin): # num = tuple(map(lambda ev: eval(str(ev)), num)) if not pgMargin or not pgPadding: - return inkex.errormsg("No padding or margin available.") + return inkex.errormsg(_("No padding or margin available.")) page_edge = list(map(sum, zip(pgMargin, pgPadding))) diff --git a/measure.py b/measure.py index 718af510544d8d1dd502e453f5bb26d595e9b9cb..2e9d8f5a2ce30502ace8c8ddd7350b438a732c48 100755 --- a/measure.py +++ b/measure.py @@ -32,6 +32,7 @@ import inkex from inkex import TextElement, TextPath, Tspan from inkex.bezier import csparea, cspcofm, csplength +from inkex.localization import inkex_gettext as _ class MeasureLength(inkex.EffectExtension): @@ -104,7 +105,7 @@ class MeasureLength(inkex.EffectExtension): # loop over all selected paths filtered = self.svg.selection.filter(inkex.PathElement) if not filtered: - raise inkex.AbortExtension("Please select at least one path object.") + raise inkex.AbortExtension(_("Please select at least one path object.")) for node in filtered: csp = node.path.transform(node.composed_transform()).to_superpath() inverse_parent_transform = -node.getparent().composed_transform() diff --git a/media_zip.py b/media_zip.py index baf7f528b29c06d5ce8bfb2496b56143f60a72ad..10fbbcd6708fdb8e9d412c046d8e13a91034822a 100755 --- a/media_zip.py +++ b/media_zip.py @@ -46,6 +46,7 @@ import zipfile import inkex from inkex import TextElement, Tspan, FlowRoot, FlowPara, FlowSpan +from inkex.localization import inkex_gettext as _ try: # PY2 from urllib import url2pathname @@ -93,7 +94,7 @@ class CompressedMedia(inkex.OutputExtension): os.path.join(self.tmp_dir, absref), image_path.encode(ENCODING) ) else: - inkex.errormsg("Could not locate file: %s" % absref) + inkex.errormsg(_("Could not locate file: %s") % absref) node.set("xlink:href", image_path) @@ -155,12 +156,14 @@ class CompressedMedia(inkex.OutputExtension): dst_file = os.path.join(self.tmp_dir, filename) with open(dst_file, "w") as stream: if len(findings) == 0: - stream.write("Didn't find any fonts in this document/selection.") + stream.write(_("Didn't find any fonts in this document/selection.")) else: if len(findings) == 1: - stream.write("Found the following font only: %s" % findings[0]) + stream.write(_("Found the following font only: %s") % findings[0]) else: - stream.write("Found the following fonts:\n%s" % "\n".join(findings)) + stream.write( + _("Found the following fonts:\n%s") % "\n".join(findings) + ) z.write(dst_file, filename) def save(self, stream): diff --git a/merge_styles.py b/merge_styles.py index 2e393b2ca131b1870be1d9fb700492344a7139de..0076f2c635ce8fac9065d78093cf5a981f6119da 100755 --- a/merge_styles.py +++ b/merge_styles.py @@ -22,6 +22,7 @@ Merges styles into class based styles and removes. """ import inkex +from inkex.localization import inkex_gettext as _ class MergeStyles(inkex.EffectExtension): @@ -53,7 +54,9 @@ class MergeStyles(inkex.EffectExtension): common = style if not common: - return inkex.errormsg("There are no common styles between these elements.") + return inkex.errormsg( + _("There are no common styles between these elements.") + ) self.svg.stylesheet.add("." + newclass, inkex.Style(sorted(common))) diff --git a/nicechart.py b/nicechart.py index 1dabc7f3af0172ad22b6725ad7df6fd357858ef0..e25865f6ef1667d46eff11683977d65372df5b86 100755 --- a/nicechart.py +++ b/nicechart.py @@ -54,6 +54,7 @@ import inkex from inkex.utils import filename_arg from inkex import Filter, TextElement, Circle, Rectangle from inkex.paths import Move, line +from inkex.localization import inkex_gettext as _ # www.sapdesignguild.org/goodies/diagram_guidelines/color_palettes.html#mss COLOUR_TABLE = { @@ -109,7 +110,7 @@ class NiceChart(inkex.GenerateExtension): @property def container_label(self): """Layer title/label""" - return "Chart-Layer: {}".format(self.options.what) + return _("Chart-Layer: {}").format(self.options.what) def add_arguments(self, pars): pars.add_argument("--tab") @@ -224,13 +225,13 @@ class NiceChart(inkex.GenerateExtension): val = float(val) if val < 0: raise inkex.AbortExtension( - "Negative values are currently not supported!" + _("Negative values are currently not supported!") ) return val if self.options.input_type == "file": if self.options.filename is None: - raise inkex.AbortExtension("Filename not specified!") + raise inkex.AbortExtension(_("Filename not specified!")) # Future: use encoding when opening the file here (if ever needed) with open(self.options.filename, "r") as fhl: @@ -252,7 +253,7 @@ class NiceChart(inkex.GenerateExtension): ) return ("Direct Input", keys, [process_value(val) for val in values]) - raise inkex.AbortExtension("Unknown input type") + raise inkex.AbortExtension(_("Unknown input type")) def get_blur(self): """Add blur to the svg and return if needed""" @@ -300,7 +301,7 @@ class NiceChart(inkex.GenerateExtension): # Process the data from a file or text box (self.title, keys, values) = self.get_data() if not values: - raise inkex.AbortExtension("No data to render into a chart.") + raise inkex.AbortExtension(_("No data to render into a chart.")) # Get the page attributes: self.width = self.svg.unittouu(self.svg.get("width")) diff --git a/output_scour.py b/output_scour.py index cffeae95466841806959bb3db33d857637767b13..185ea97a16220c9ce01d41b95161dfbbdddb4969 100755 --- a/output_scour.py +++ b/output_scour.py @@ -5,15 +5,18 @@ Run the scour module on the svg output. import inkex +from inkex.localization import inkex_gettext as _ try: from packaging.version import Version except ImportError: raise inkex.DependencyError( - """Failed to import module 'packaging'. + _( + """Failed to import module 'packaging'. Please make sure it is installed (e.g. using 'pip install packaging' or 'sudo apt-get install python3-packaging') and try again. """ + ) ) try: @@ -21,10 +24,12 @@ try: from scour.scour import scourString except ImportError: raise inkex.DependencyError( - """Failed to import module 'scour'. + _( + """Failed to import module 'scour'. Please make sure it is installed (e.g. using 'pip install scour' or 'sudo apt-get install python3-scour') and try again. """ + ) ) diff --git a/path_number_nodes.py b/path_number_nodes.py index 1f7dc1c71c79d29504163e7ddad7e10eee128189..77d61be9c767f454c44ed5778e7ad1377e5c95e0 100755 --- a/path_number_nodes.py +++ b/path_number_nodes.py @@ -21,6 +21,7 @@ import math import inkex from inkex import TextElement, Circle +from inkex.localization import inkex_gettext as _ class NumberNodes(inkex.EffectExtension): @@ -42,7 +43,7 @@ class NumberNodes(inkex.EffectExtension): def effect(self): filtered = self.svg.selection.filter(inkex.PathElement) if not filtered: - raise inkex.AbortExtension("Please select at least one path object.") + raise inkex.AbortExtension(_("Please select at least one path object.")) for node in filtered: self.add_dot(node) diff --git a/pathalongpath.py b/pathalongpath.py index 8a3b1f6c4d6186230b505159e21cf1feced7b141..9c4bac5dc921615e47d6b4b4337d3a4167813e8d 100755 --- a/pathalongpath.py +++ b/pathalongpath.py @@ -37,6 +37,7 @@ import math import inkex from inkex.bezier import tpoint from inkex.paths import CubicSuperPath +from inkex.localization import inkex_gettext as _ import pathmodifier @@ -112,7 +113,7 @@ class PathAlongPath(pathmodifier.PathModifier): def effect(self): if len(self.options.ids) < 2: - raise inkex.AbortExtension("This extension requires two selected paths.") + raise inkex.AbortExtension(_("This extension requires two selected paths.")) self.options.wave = self.options.kind == "Ribbon" if self.options.copymode == "Single": @@ -131,7 +132,7 @@ class PathAlongPath(pathmodifier.PathModifier): patterns, skels = self.get_patterns_and_skeletons(True, self.options.duplicate) bboxes = [pattern.bounding_box() for pattern in patterns.values()] if None in bboxes: # for texts, we can't compute the bounding box - raise inkex.AbortExtension("Please convert texts to path first") + raise inkex.AbortExtension(_("Please convert texts to path first")) bbox = sum(bboxes, None) if self.options.vertical: @@ -142,8 +143,10 @@ class PathAlongPath(pathmodifier.PathModifier): delta_x = width + self.options.space if delta_x < 0.01: raise inkex.AbortExtension( - "The total length of the pattern is too small\n" - "Please choose a larger object or set 'Space between copies' > 0" + _( + "The total length of the pattern is too small\n" + "Please choose a larger object or set 'Space between copies' > 0" + ) ) for pattern in patterns.values(): if isinstance(pattern, inkex.PathElement): @@ -191,7 +194,10 @@ class PathAlongPath(pathmodifier.PathModifier): if self.options.stretch: if not bbox.width: raise inkex.AbortExtension( - "The 'stretch' option requires that the pattern must have non-zero width :\nPlease edit the pattern width." + _( + "The 'stretch' option requires that the pattern must " + "have non-zero width :\nPlease edit the pattern width." + ) ) for sub in path: self.stretch(sub, length / bbox.width, 1, skelcomp[0]) diff --git a/pathscatter.py b/pathscatter.py index 8edd72cf2e44006b651cc480046377cc32b93703..7ffee63dd17cf34f4199e46678ead775fc572c7c 100755 --- a/pathscatter.py +++ b/pathscatter.py @@ -103,7 +103,7 @@ class PathScatter(pathmodifier.Diffeo): type=str, dest="copymode", default="move", - help="""How the pattern is duplicated. Default: 'move', + help="""How the pattern is duplicated. Default: 'move', Options: 'clone', 'duplicate', 'move'""", ) self.arg_parser.add_argument( @@ -167,10 +167,12 @@ class PathScatter(pathmodifier.Diffeo): dx = width + self.options.space if dx < 0.01: if isinstance(original_pattern_node, inkex.TextElement): - raise inkex.AbortExtension("Please convert texts to path first") + raise inkex.AbortExtension(_("Please convert texts to path first")) raise inkex.AbortExtension( - "The total length of the pattern is too small\n" - "Please choose a larger object or set 'Space between copies' > 0" + _( + "The total length of the pattern is too small\n" + "Please choose a larger object or set 'Space between copies' > 0" + ) ) # check if group and expand it diff --git a/perspective.py b/perspective.py index c6af4037edf4a8abd23be1e60206047b31f4e979..940e42e30bbed6468acaf69d149c7ba5ee32e6ec 100755 --- a/perspective.py +++ b/perspective.py @@ -41,8 +41,8 @@ class Perspective(inkex.EffectExtension): if np is None: raise inkex.AbortExtension( _( - "Failed to import the numpy or numpy.linalg modules." - " These modules are required by this extension. Please install them." + "Failed to import the numpy or numpy.linalg modules. " + "These modules are required by this extension. Please install them." " On a Debian-like system this can be done with the command, " "sudo apt-get install python-numpy." ) @@ -63,7 +63,8 @@ class Perspective(inkex.EffectExtension): if len(path) < 1 or len(path[0]) < 4: raise inkex.AbortExtension( _( - "This extension requires that the second path be four nodes long." + "This extension requires that the second path be four " + "nodes long." ) ) @@ -101,8 +102,8 @@ class Perspective(inkex.EffectExtension): else: raise inkex.AbortExtension( _( - "The first selected object is neither a path nor a group.\nTry using" - " the procedure Path->Object to Path." + "The first selected object is neither a path nor a group.\nTry " + "using the procedure Path->Object to Path." ) ) diff --git a/pixelsnap.py b/pixelsnap.py index 471da70a7e7a7e89becc25e24420048b72e143bf..e414af68058849e5ae6b5558c001ec9ac245fcf7 100755 --- a/pixelsnap.py +++ b/pixelsnap.py @@ -70,6 +70,7 @@ import sys import inkex from inkex import PathElement, Group, Image, Rectangle, ShapeElement, Transform +from inkex.localization import inkex_gettext as _ Precision = 5 # number of digits of precision for comparing float numbers @@ -171,7 +172,7 @@ class PixelSnap(inkex.EffectExtension): if abs(abs(transform.a) - abs(transform.d)) > (10**-Precision): raise TransformError( - "Selection contains non-symetric scaling" + _("Selection contains non-symetric scaling") ) # *** wouldn't be hard to get around this by calculating vertical_offset & horizontal_offset separately, maybe 1 functions, or maybe returning a tuple stroke_width = transform_dimensions(transform, width=stroke_width) @@ -302,7 +303,7 @@ class PixelSnap(inkex.EffectExtension): # if we've got any skew/rotation, get outta here if transform.c or transform.b: raise TransformError( - "TR: Selection contains transformations with skew/rotation" + _("TR: Selection contains transformations with skew/rotation") ) trm = list(transform.to_hexad()) @@ -319,7 +320,7 @@ class PixelSnap(inkex.EffectExtension): if abs(abs(transform.a) - abs(transform.d)) > (10**-Precision): raise TransformError( - "Selection contains non-symetric scaling, can't snap stroke width" + _("Selection contains non-symetric scaling, can't snap stroke width") ) if stroke_width: @@ -337,7 +338,7 @@ class PixelSnap(inkex.EffectExtension): if transform.c or transform.b: # if we've got any skew/rotation, get outta here raise TransformError( - "Path: Selection contains transformations with skew/rotation" + _("Path: Selection contains transformations with skew/rotation") ) offset = self.stroke_width_offset(elem, parent_transform) % 1 @@ -405,7 +406,7 @@ class PixelSnap(inkex.EffectExtension): if transform.c or transform.b: # if we've got any skew/rotation, get outta here raise TransformError( - "Rect: Selection contains transformations with skew/rotation" + _("Rect: Selection contains transformations with skew/rotation") ) offset = self.stroke_width_offset(elem, parent_transform) % 1 diff --git a/polyhedron_3d.py b/polyhedron_3d.py index fe544d08735a9b0b9d392ac00e9ddcdb10e24b45..4d1f61c4fcd6dcc9ac09b6252691217787d7eb2b 100755 --- a/polyhedron_3d.py +++ b/polyhedron_3d.py @@ -57,6 +57,7 @@ import inkex from inkex.utils import pairwise from inkex import Group, Circle from inkex.paths import Move, Line +from inkex.localization import inkex_gettext as _ try: import numpy @@ -228,7 +229,7 @@ class WavefrontObj(object): def _parse_file(self, filename): if not os.path.isfile(filename): - raise IOError("Can't find wavefront object file {}".format(filename)) + raise IOError(_("Can't find wavefront object file {}").format(filename)) with open(filename, "r") as fhl: for line in fhl: self._parse_line(line.strip()) @@ -343,7 +344,7 @@ class Poly3D(inkex.GenerateExtension): def generate(self): if numpy is None: - raise inkex.AbortExtension("numpy is required.") + raise inkex.AbortExtension(_("numpy is required.")) so = self.options obj = WavefrontObj(self.get_filename()) @@ -416,7 +417,7 @@ class Poly3D(inkex.GenerateExtension): draw_faces(z_list, transformed_pts, obj, so.shade, fill_col, st, poly) else: # we cannot generate a list of faces from the edges without a lot of computation - raise inkex.AbortExtension("Face data not found.") + raise inkex.AbortExtension(_("Face data not found.")) @staticmethod def z_sort_max(pts, face): diff --git a/render_barcode_datamatrix.py b/render_barcode_datamatrix.py index 1252336d348bcf9c8cff50938c0703635bf6f28e..5b3906cde0401ff11e466edbff40a09373a4f9a2 100755 --- a/render_barcode_datamatrix.py +++ b/render_barcode_datamatrix.py @@ -46,6 +46,7 @@ The basis processing flow is; import inkex from inkex import Rectangle +from inkex.localization import inkex_gettext as _ INVALID_BIT = 2 @@ -526,7 +527,7 @@ class DataMatrix(inkex.GenerateExtension): try: return SYMBOLS[value] except KeyError: - raise inkex.AbortExtension("Invalid symbol size.") + raise inkex.AbortExtension(_("Invalid symbol size.")) def generate(self): size = str(self.options.size) @@ -534,7 +535,7 @@ class DataMatrix(inkex.GenerateExtension): attribs = {"style": str(style), "height": size, "width": size} if not self.options.text: - raise inkex.AbortExtension("Please enter an input string.") + raise inkex.AbortExtension(_("Please enter an input string.")) # create a 2d list corresponding to the 1's and 0s of the DataMatrix encoded = self.encode(self.options.text, *self.options.symbol) @@ -580,7 +581,7 @@ class DataMatrix(inkex.GenerateExtension): if line[y][x] == 1: # A binary 1 is a filled square yield (x * size + i * spacing, y * size) elif line[y][x] == INVALID_BIT: # we have an invalid bit value - inkex.errormsg("Invalid bit value, {}!".format(line[y][x])) + inkex.errormsg(_("Invalid bit value, {}!").format(line[y][x])) if __name__ == "__main__": diff --git a/render_barcode_qrcode.py b/render_barcode_qrcode.py index 83efa58113cd56fc32932f259dd2442bd0f4b281..0493e71fe57029357e4061011016a977cdc813ca 100755 --- a/render_barcode_qrcode.py +++ b/render_barcode_qrcode.py @@ -29,6 +29,7 @@ from itertools import product import inkex from inkex import Group, Rectangle, Use, PathElement +from inkex.localization import inkex_gettext as _ class QRLengthError(Exception): @@ -1118,9 +1119,9 @@ class QrCode(inkex.GenerateExtension): opt = self.options if not opt.text: - raise inkex.AbortExtension("Please enter an input text") + raise inkex.AbortExtension(_("Please enter an input text")) elif opt.drawtype == "symbol" and opt.symbolid == "": - raise inkex.AbortExtension("Please enter symbol id") + raise inkex.AbortExtension(_("Please enter symbol id")) # for Python 3 ugly hack to represent bytes as str for Python2 compatibility text_str = str(opt.text) @@ -1260,13 +1261,15 @@ class QrCode(inkex.GenerateExtension): if len(self.svg.selection) > 0: self.options.symbolid = self.svg.selection.first().get_id() else: - raise inkex.AbortExtension("Please select an element to clone") + raise inkex.AbortExtension(_("Please select an element to clone")) return self.render_symbol() def render_symbol(self): symbol = self.svg.getElementById(self.options.symbolid) if symbol is None: - raise inkex.AbortExtension(f"Can't find symbol {self.options.symbolid}") + raise inkex.AbortExtension( + _("Can't find symbol {}").format(self.options.symbolid) + ) bbox = symbol.path.bounding_box() transform = inkex.Transform( scale=( diff --git a/replace_font.py b/replace_font.py index 98f291e967757488f97a879a7c4f9226787a75e6..37b5bde63fbf335a1d51adc188482f49fdb7b00b 100755 --- a/replace_font.py +++ b/replace_font.py @@ -26,6 +26,7 @@ It can also replace all fonts indiscriminately, and list all fonts currently being used. """ import inkex +from inkex.localization import inkex_gettext as _ text_tags = [ "{http://www.w3.org/2000/svg}tspan", @@ -113,7 +114,8 @@ def report_replacements(num): if num == 0: inkex.errormsg( _( - "Couldn't find anything using that font, please ensure the spelling and spacing is correct." + "Couldn't find anything using that font, please ensure the spelling " + "and spacing is correct." ) ) @@ -210,7 +212,7 @@ class ReplaceFont(inkex.EffectExtension): def effect(self): if not self.options.action: - return inkex.errormsg("Nothing to do, no action specified.") + return inkex.errormsg(_("Nothing to do, no action specified.")) action = self.options.action.strip( '"' ) # TODO Is this a bug? (Extra " characters) diff --git a/restack.py b/restack.py index 5e302bae3da51661ba39bb6d5ea2b9ad482977c6..0f991e1a2dc19ea228dfe9f608a56f8a26235f4f 100755 --- a/restack.py +++ b/restack.py @@ -26,6 +26,7 @@ import random import inkex from inkex.utils import KeyDict from inkex import SvgDocumentElement +from inkex.localization import inkex_gettext as _ # Old settings, supported because users click 'ok' without looking. XAN = KeyDict({"l": "left", "r": "right", "m": "center_x"}) @@ -53,7 +54,7 @@ class Restack(inkex.EffectExtension): def effect(self): if not self.svg.selection: - raise inkex.AbortExtension("There is no selection to restack.") + raise inkex.AbortExtension(_("There is no selection to restack.")) # process selection to get list of objects to be arranged parentnode = None diff --git a/scribus_export_pdf.py b/scribus_export_pdf.py index 4641b9bdd4a5a2bab85a6143c5d9bee3a761838b..a03952e6dffc441cd5255876fd935c7ca93a7b78 100644 --- a/scribus_export_pdf.py +++ b/scribus_export_pdf.py @@ -26,6 +26,7 @@ import inkex from inkex import AbortExtension from inkex.base import TempDirMixin from inkex.command import take_snapshot, call +from inkex.localization import inkex_gettext as _ SCRIBUS_EXE = "scribus" @@ -89,7 +90,7 @@ class Scribus(TempDirMixin, inkex.OutputExtension): colorMarks = self.options.colorMarks if (bleedMarks or colorMarks) and margin < 7: raise AbortExtension( - "You need at least 7mm bleed to show cutting marks or color marks" + _("You need at least 7mm bleed to show cutting marks or color marks") ) if bleedMarks or colorMarks: margin = ( @@ -148,14 +149,16 @@ exportPDF()""" version_match = VERSION_REGEX.search(scribus_version) if version_match is None: raise AbortExtension( - f"Could not detect Scribus version ({scribus_version})" + _("Could not detect Scribus version ()").format(scribus_version) ) major = int(version_match.group(1)) minor = int(version_match.group(2)) point = int(version_match.group(3)) if (major < 1) or (major == 1 and minor < 5): raise AbortExtension( - f"Found Scribus {version_match.group(0)}. This extension requires Scribus 1.5.x." + _("Found Scribus {}. This extension requires Scribus 1.5.x.").format( + version_match.group(0) + ) ) input_file = self.options.input_file @@ -164,11 +167,14 @@ exportPDF()""" profiles = self.svg.defs.findall("svg:color-profile") if len(profiles) == 0: raise AbortExtension( - "Please select a color profile in the document settings." + __("Please select a color profile in the document settings.") ) elif len(profiles) > 1: raise AbortExtension( - "Please only link a single color profile in the document settings. No output generated." + _( + "Please only link a single color profile in the document settings. " + "No output generated." + ) ) iccPath = profiles[0].get("xlink:href") diff --git a/svgcalendar.py b/svgcalendar.py index 6339cf645b264741c91ce13d8d230700a6266405..a21fd49a77d032d38a2815231b25e64a922863bd 100755 --- a/svgcalendar.py +++ b/svgcalendar.py @@ -36,6 +36,7 @@ import sys import inkex from inkex import TextElement +from inkex.localization import inkex_gettext as _ if sys.version_info[0] > 2: @@ -385,7 +386,7 @@ class Calendar(inkex.EffectExtension): self.options.month_names[m - 1], self.options.input_encode ) except: - raise ValueError("You must select a correct system encoding.") + raise ValueError(_("You must select a correct system encoding.")) week_group = g.add(inkex.Group()) week_x = 0 @@ -409,7 +410,7 @@ class Calendar(inkex.EffectExtension): wday, self.options.input_encode ) except: - raise ValueError("You must select a correct system encoding.") + raise ValueError(_("You must select a correct system encoding.")) week_x += 1 diff --git a/text_split.py b/text_split.py index 1b1b0c17663368295d4b8a6d12c4645ea7242c79..dee9c884c720e76388d33851517bdc2e0e0b4fbe 100755 --- a/text_split.py +++ b/text_split.py @@ -174,8 +174,8 @@ class TextSplit(inkex.EffectExtension): raise TypeError( _( "Element {} uses a flow region that is not a rectangle. " - "First unflow text.".format(element.get_id()) - ) + "First unflow text." + ).format(element.get_id()) ) for child in oldelement: if isinstance(child, FlowPara): diff --git a/triangle.py b/triangle.py index d8abb97b771ac9e8a4e222176a8c4e3b7dc85466..a9f2812f3555fd4785ec4f7d2c64f5fb977ba3b2 100755 --- a/triangle.py +++ b/triangle.py @@ -37,6 +37,7 @@ import sys from math import acos, asin, cos, pi, sin, sqrt import inkex +from inkex.localization import inkex_gettext as _ X, Y = range(2) @@ -122,7 +123,7 @@ def draw_tri_from_3_sides( draw_SVG_tri(a, b, c, offset, width, "Triangle", parent) else: - inkex.errormsg("Invalid Triangle Specifications.") + inkex.errormsg(_("Invalid Triangle Specifications.")) class Triangle(inkex.EffectExtension): diff --git a/web_interactive_mockup.py b/web_interactive_mockup.py index 8f0e591f7506a338cf32ffafebb513e5441a5c9c..4827140481fc6b598adc1c3ff60c22460d0deabc 100755 --- a/web_interactive_mockup.py +++ b/web_interactive_mockup.py @@ -18,6 +18,7 @@ # import inkwebeffect import inkex +from inkex.localization import inkex_gettext as _ class InteractiveMockup(inkwebeffect.InkWebEffect): @@ -32,7 +33,10 @@ class InteractiveMockup(inkwebeffect.InkWebEffect): if len(self.options.ids) < 2: raise inkex.AbortExtension( - "You must select at least two elements. The last one is the object you want to go to." + _( + "You must select at least two elements. " + "The last one is the object you want to go to." + ) ) el_from = list(self.svg.selection.values())[:-1] diff --git a/wireframe_sphere.py b/wireframe_sphere.py index 7c4142d35c1f449e543be0a329ff86037c6584eb..d94f0928dd80c0b3c3b865a5bfe33afe93d2aecc 100755 --- a/wireframe_sphere.py +++ b/wireframe_sphere.py @@ -52,6 +52,7 @@ sphere were opaque. from math import acos, atan, cos, pi, sin, tan import inkex +from inkex.localization import inkex_gettext as _ # add a tiny value to the ellipse radii, so that if we get a # zero radius, the ellipse still shows up as a line @@ -84,7 +85,7 @@ class WireframeSphere(inkex.GenerateExtension): # PARAMETER PROCESSING if opt.NUM_LONG % 2 != 0: # lines of longitude are odd : abort - inkex.errormsg("Please enter an even number of lines of longitude.") + inkex.errormsg(_("Please enter an even number of lines of longitude.")) return radius = self.svg.unittouu(str(opt.RADIUS) + "px")