diff options
| author | Lex Neva <lexelby@users.noreply.github.com> | 2018-02-04 22:38:24 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-02-04 22:38:24 -0500 |
| commit | 72d52dc317b562f728b772f058ab2c5059a2a618 (patch) | |
| tree | 8c975a567e99d89514b6b49430b5b439d800f3e4 /inkstitch.py | |
| parent | 1dd76646cc5379e686a1c8785a4dc38b6e24c931 (diff) | |
framework for translations (#55)
sets up all the plumbing to send strings to CrowdIn for translation and incorporate the results
Diffstat (limited to 'inkstitch.py')
| -rw-r--r-- | inkstitch.py | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/inkstitch.py b/inkstitch.py index 06e26bb3..c53781fc 100644 --- a/inkstitch.py +++ b/inkstitch.py @@ -1,7 +1,9 @@ #!/usr/bin/env python # http://www.achatina.de/sewing/main/TECHNICL.HTM +import os import sys +import gettext from copy import deepcopy import math import libembroidery @@ -31,10 +33,28 @@ EMBROIDERABLE_TAGS = (SVG_PATH_TAG, SVG_POLYLINE_TAG) dbg = open("/tmp/embroider-debug.txt", "w") +_ = lambda message: message + # simplify use of lru_cache decorator def cache(*args, **kwargs): return lru_cache(maxsize=None)(*args, **kwargs) +def localize(): + if getattr(sys, 'frozen', False): + # we are in a pyinstaller installation + locale_dir = sys._MEIPASS + else: + locale_dir = os.path.dirname(__file__) + + locale_dir = os.path.join(locale_dir, 'locales') + + translation = gettext.translation("inkstitch", locale_dir, fallback=True) + + global _ + _ = translation.gettext + +localize() + # cribbed from inkscape-silhouette def parse_length_with_units( str ): @@ -71,7 +91,7 @@ def parse_length_with_units( str ): try: v = float( s ) except: - raise ValueError("parseLengthWithUnits: unknown unit %s" % s) + raise ValueError(_("parseLengthWithUnits: unknown unit %s") % s) return v, u @@ -95,7 +115,7 @@ def convert_length(length): # open an old document, inkscape will add a viewbox for you. return value * 96 - raise ValueError("Unknown unit: %s" % units) + raise ValueError(_("Unknown unit: %s") % units) @cache @@ -298,8 +318,8 @@ class EmbroideryElement(object): @property @param('trim_after', - 'TRIM after', - tooltip='Trim thread after this object (for supported machines and file formats)', + _('TRIM after'), + tooltip=_('Trim thread after this object (for supported machines and file formats)'), type='boolean', default=False, sort_index=1000) @@ -308,8 +328,8 @@ class EmbroideryElement(object): @property @param('stop_after', - 'STOP after', - tooltip='Add STOP instruction after this object (for supported machines and file formats)', + _('STOP after'), + tooltip=_('Add STOP instruction after this object (for supported machines and file formats)'), type='boolean', default=False, sort_index=1000) |
