diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | babel.conf | 2 | ||||
| -rw-r--r-- | lib/i18n.py | 10 | ||||
| -rw-r--r-- | lib/inx/generate.py | 10 | ||||
| -rw-r--r-- | lib/inx/utils.py | 29 | ||||
| -rw-r--r-- | messages.po | 106 | ||||
| -rw-r--r-- | templates/convert_to_satin.inx | 6 | ||||
| -rw-r--r-- | templates/embroider.inx | 14 | ||||
| -rw-r--r-- | templates/flip.inx | 8 | ||||
| -rw-r--r-- | templates/input.inx | 4 | ||||
| -rw-r--r-- | templates/install.inx | 8 | ||||
| -rw-r--r-- | templates/layer_commands.inx | 14 | ||||
| -rw-r--r-- | templates/object_commands.inx | 14 | ||||
| -rw-r--r-- | templates/output.inx | 4 | ||||
| -rw-r--r-- | templates/params.inx | 8 | ||||
| -rw-r--r-- | templates/print.inx | 8 | ||||
| -rw-r--r-- | templates/simulate.inx | 8 | ||||
| -rw-r--r-- | templates/zip.inx | 6 |
18 files changed, 207 insertions, 54 deletions
@@ -24,7 +24,7 @@ distclean: rm -rf build dist *.spec *.tar.gz .PHONY: inx -inx: +inx: locales mkdir -p inx bin/generate-inx-files @@ -3,4 +3,4 @@ [python: **.py] [jinja2: print/templates/*.html] - +[jinja2: templates/*] diff --git a/lib/i18n.py b/lib/i18n.py index 06e0dd49..419c03dc 100644 --- a/lib/i18n.py +++ b/lib/i18n.py @@ -1,26 +1,32 @@ import sys import os +from os.path import dirname, realpath import gettext _ = translation = None +locale_dir = None # Use N_ to mark a string for translation but _not_ immediately translate it. # reference: https://docs.python.org/3/library/gettext.html#deferred-translations # Makefile configures pybabel to treat N_() the same as _() def N_(message): return message -def localize(): +def _set_locale_dir(): + global locale_dir + if getattr(sys, 'frozen', False): # we are in a pyinstaller installation locale_dir = sys._MEIPASS else: - locale_dir = os.path.dirname(__file__) + locale_dir = dirname(dirname(realpath(__file__))) locale_dir = os.path.join(locale_dir, 'locales') +def localize(languages=None): global translation, _ translation = gettext.translation("inkstitch", locale_dir, fallback=True) _ = translation.gettext +_set_locale_dir() localize() diff --git a/lib/inx/generate.py b/lib/inx/generate.py index 4773a92d..f9ed799b 100644 --- a/lib/inx/generate.py +++ b/lib/inx/generate.py @@ -1,8 +1,12 @@ +import os + from .inputs import generate_input_inx_files from .outputs import generate_output_inx_files from .extensions import generate_extension_inx_files +from .utils import iterate_inx_locales, inx_path def generate_inx_files(): - generate_input_inx_files() - generate_output_inx_files() - generate_extension_inx_files() + for locale in iterate_inx_locales(): + generate_input_inx_files() + generate_output_inx_files() + generate_extension_inx_files() diff --git a/lib/inx/utils.py b/lib/inx/utils.py index da0a4614..6103f360 100644 --- a/lib/inx/utils.py +++ b/lib/inx/utils.py @@ -1,14 +1,18 @@ import os +import gettext from os.path import dirname from jinja2 import Environment, FileSystemLoader -from ..i18n import translation as inkstitch_translation +from ..i18n import translation as default_translation, locale_dir, _, N_ _top_path = dirname(dirname(dirname(os.path.realpath(__file__)))) inx_path = os.path.join(_top_path, "inx") template_path = os.path.join(_top_path, "templates") +current_translation = default_translation +current_locale = "en_US" + def build_environment(): env = Environment( loader = FileSystemLoader(template_path), @@ -16,11 +20,30 @@ def build_environment(): extensions=['jinja2.ext.i18n'] ) - env.install_gettext_translations(inkstitch_translation) + env.install_gettext_translations(current_translation) + env.globals["locale"] = current_locale return env def write_inx_file(name, contents): - inx_file_name = "inkstitch_%s.inx" % name + inx_file_name = "inkstitch_%s_%s.inx" % (name, current_locale) with open(os.path.join(inx_path, inx_file_name), 'w') as inx_file: print >> inx_file, contents + +def iterate_inx_locales(): + global current_translation, current_locale + + locales = sorted(os.listdir(locale_dir)) + for locale in locales: + translation = gettext.translation("inkstitch", locale_dir, languages=[locale], fallback=True) + + # L10N If you translate this string, that will tell Ink/Stitch to + # generate menu items for this language in Inkscape's "Extensions" + # menu. + magic_string = N_("Generate INX files") + translated_magic_string = translation.gettext(magic_string) + + if translated_magic_string != magic_string or locale == "en_US": + current_translation = translation + current_locale = locale + yield locale diff --git a/messages.po b/messages.po index 0dcd185a..074159c4 100644 --- a/messages.po +++ b/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2018-08-20 15:49-0400\n" +"POT-Creation-Date: 2018-08-20 20:42-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" @@ -608,6 +608,13 @@ msgstr "" msgid "No embroidery file formats selected." msgstr "" +#. If you translate this string, that will tell Ink/Stitch to +#. generate menu items for this language in Inkscape's "Extensions" +#. menu. +#: lib/inx/utils.py:43 +msgid "Generate INX files" +msgstr "" + #: lib/simulator.py:40 msgid "Speed up" msgstr "" @@ -844,7 +851,7 @@ msgstr "" msgid "Ink/Stitch Print Preview" msgstr "" -#: print/templates/ui.html:4 +#: print/templates/ui.html:4 templates/print.inx:3 msgid "Print" msgstr "" @@ -1102,3 +1109,98 @@ msgstr "" msgid "Brother Stitch Format" msgstr "" +#: templates/convert_to_satin.inx:3 +msgid "Convert Line to Satin" +msgstr "" + +#: templates/convert_to_satin.inx:12 templates/embroider.inx:23 +#: templates/flip.inx:12 templates/install.inx:12 +#: templates/layer_commands.inx:16 templates/object_commands.inx:14 +#: templates/params.inx:12 templates/print.inx:12 templates/simulate.inx:12 +msgid "English" +msgstr "" + +#: templates/embroider.inx:3 +msgid "Embroider" +msgstr "" + +#: templates/embroider.inx:7 +msgid "Collapse length (mm)" +msgstr "" + +#: templates/embroider.inx:7 +msgid "Jump stitches smaller than this will be treated as normal stitches." +msgstr "" + +#: templates/embroider.inx:8 +msgid "Hide other layers" +msgstr "" + +#: templates/embroider.inx:8 +msgid "" +"Hide all other top-level layers when the embroidery layer is generated, " +"in order to make stitching discernible." +msgstr "" + +#: templates/embroider.inx:9 +msgid "Output file format" +msgstr "" + +#: templates/embroider.inx:14 +msgid "DEBUG" +msgstr "" + +#: templates/embroider.inx:17 +msgid "Directory" +msgstr "" + +#: templates/embroider.inx:17 +msgid "Leave empty to save the output in Inkscape's extension directory." +msgstr "" + +#: templates/flip.inx:3 +msgid "Flip Satin Columns" +msgstr "" + +#: templates/input.inx:11 +#, python-format +msgid "convert %(file_extension)s file to Ink/Stitch manual-stitch paths" +msgstr "" + +#: templates/install.inx:3 +msgid "Install add-ons for Inkscape" +msgstr "" + +#: templates/layer_commands.inx:3 +msgid "Add Layer Commands" +msgstr "" + +#: templates/layer_commands.inx:7 +msgid "Commands will be added to the currently-selected layer." +msgstr "" + +#: templates/object_commands.inx:3 +msgid "Attach Commands" +msgstr "" + +#: templates/output.inx:11 +#, python-format +msgid "Save design in %(file_extension)s format using Ink/Stitch" +msgstr "" + +#: templates/params.inx:3 +msgid "Params" +msgstr "" + +#: templates/simulate.inx:3 +msgid "Simulate" +msgstr "" + +#: templates/zip.inx:10 +msgid "Ink/Stitch: ZIP export multiple formats (.zip)" +msgstr "" + +#: templates/zip.inx:11 +msgid "Create a ZIP with multiple embroidery file formats using Ink/Stitch" +msgstr "" + diff --git a/templates/convert_to_satin.inx b/templates/convert_to_satin.inx index 446e4b5c..50886d4a 100644 --- a/templates/convert_to_satin.inx +++ b/templates/convert_to_satin.inx @@ -1,14 +1,16 @@ <?xml version="1.0" encoding="UTF-8"?> <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> <name>{% trans %}Convert Line to Satin{% endtrans %}</name> - <id>org.inkstitch.convert_to_satin</id> + <id>org.inkstitch.convert_to_satin.{{ locale }}</id> <dependency type="executable" location="extensions">inkstitch.py</dependency> <dependency type="executable" location="extensions">inkex.py</dependency> <param name="extension" type="string" gui-hidden="true">convert_to_satin</param> <effect> <object-type>all</object-type> <effects-menu> - <submenu name="Ink/Stitch" /> + <submenu name="Ink/Stitch"> + <submenu name="{% trans %}English{% endtrans %}" /> + </submenu> </effects-menu> </effect> <script> diff --git a/templates/embroider.inx b/templates/embroider.inx index f4a78d73..d89b4d6f 100644 --- a/templates/embroider.inx +++ b/templates/embroider.inx @@ -1,12 +1,12 @@ <?xml version="1.0" encoding="UTF-8"?> <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> <name>{% trans %}Embroider{% endtrans %}</name> - <id>org.inkstitch.embroider</id> + <id>org.inkstitch.embroider.{{ locale }}</id> <dependency type="executable" location="extensions">inkstitch.py</dependency> <dependency type="executable" location="extensions">inkex.py</dependency> - <param name="collapse_len_mm" type="float" min="0.0" max="10.0" gui-text="{% trans %}Collapse length (mm){% endtrans %}" gui-description="{% trans %}Jump stitches smaller than this will be treated as normal stitches.{% endtrans %}">3.0</param> - <param name="hide_layers" type="boolean" gui-text="{% trans %}Hide other layers{% endtrans %}" gui-description="{% trans %}Hide all other top-level layers when the embroidery layer is generated, in order to make stitching discernible.{% endtrans %}">true</param> - <param name="output_format" type="optiongroup" gui-text="{% trans %}Output file format{% endtrans %}" appearance="minimal"> + <param name="collapse_len_mm" type="float" min="0.0" max="10.0" _gui-text="{% trans %}Collapse length (mm){% endtrans %}" _gui-description="{% trans %}Jump stitches smaller than this will be treated as normal stitches.{% endtrans %}">3.0</param> + <param name="hide_layers" type="boolean" _gui-text="{% trans %}Hide other layers{% endtrans %}" _gui-description="{% trans %}Hide all other top-level layers when the embroidery layer is generated, in order to make stitching discernible.{% endtrans %}">true</param> + <param name="output_format" type="optiongroup" _gui-text="{% trans %}Output file format{% endtrans %}" appearance="minimal"> {% for format, description in formats %} <_option value="{{ format }}">{{ _(description) }} ({{ format | upper }})</_option> {% endfor %} @@ -14,12 +14,14 @@ <_option value="{{ format }}">{{ _(description) }} ({{ format | upper }}) [{{ _("DEBUG") }}]</_option> {% endfor %} </param> - <param name="path" type="string" gui-text="{% trans %}Directory{% endtrans %}" gui-description="{% trans %}Leave empty to save the output in Inkscape's extension directory.{% endtrans %}"></param> + <param name="path" type="string" _gui-text="{% trans %}Directory{% endtrans %}" _gui-description="{% trans %}Leave empty to save the output in Inkscape's extension directory.{% endtrans %}"></param> <param name="extension" type="string" gui-hidden="true">embroider</param> <effect> <object-type>all</object-type> <effects-menu> - <submenu name="Ink/Stitch"/> + <submenu name="Ink/Stitch"> + <submenu name="{% trans %}English{% endtrans %}" /> + </submenu> </effects-menu> </effect> <script> diff --git a/templates/flip.inx b/templates/flip.inx index 6ce7c6ef..22bcdd36 100644 --- a/templates/flip.inx +++ b/templates/flip.inx @@ -1,14 +1,16 @@ <?xml version="1.0" encoding="UTF-8"?> <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> - <name>{% trans %}Flip Satin Columns{% endtrans %}</name> - <id>org.inkstitch.flip_satins</id> + <name>{% trans %}Flip Satin Columns{% endtrans %}</_name> + <id>org.inkstitch.flip_satins.{{ locale }}</id> <dependency type="executable" location="extensions">inkstitch.py</dependency> <dependency type="executable" location="extensions">inkex.py</dependency> <param name="extension" type="string" gui-hidden="true">flip</param> <effect> <object-type>all</object-type> <effects-menu> - <submenu name="Ink/Stitch"/> + <submenu name="Ink/Stitch"> + <submenu name="{% trans %}English{% endtrans %}" /> + </submenu> </effects-menu> </effect> <script> diff --git a/templates/input.inx b/templates/input.inx index 1e50d841..d2a0d678 100644 --- a/templates/input.inx +++ b/templates/input.inx @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> - <name>{{ format | upper }} file input</name> - <id>org.inkstitch.input.{{ format }}</id> + <name>{{ format | upper }} file input</_name> + <id>org.inkstitch.input.{{ format }}.{{ locale }}</id> <dependency type="executable" location="extensions">inkstitch.py</dependency> <dependency type="executable" location="extensions">inkex.py</dependency> <input> diff --git a/templates/install.inx b/templates/install.inx index 9ee020fe..503e1e03 100644 --- a/templates/install.inx +++ b/templates/install.inx @@ -1,14 +1,16 @@ <?xml version="1.0" encoding="UTF-8"?> <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> - <name>{% trans %}Install add-ons for Inkscape{% endtrans %}</name> - <id>org.inkstitch.install</id> + <name>{% trans %}Install add-ons for Inkscape{% endtrans %}</_name> + <id>org.inkstitch.install.{{ locale }}</id> <dependency type="executable" location="extensions">inkstitch.py</dependency> <dependency type="executable" location="extensions">inkex.py</dependency> <param name="extension" type="string" gui-hidden="true">install</param> <effect> <object-type>all</object-type> <effects-menu> - <submenu name="Ink/Stitch"/> + <submenu name="Ink/Stitch"> + <submenu name="{% trans %}English{% endtrans %}" /> + </submenu> </effects-menu> </effect> <script> diff --git a/templates/layer_commands.inx b/templates/layer_commands.inx index e04d2540..acf0f199 100644 --- a/templates/layer_commands.inx +++ b/templates/layer_commands.inx @@ -1,19 +1,21 @@ <?xml version="1.0" encoding="UTF-8"?> <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> - <name>{% trans %}Add Layer Commands{% endtrans %}</name> - <id>org.inkstitch.layer_commands</id> + <name>{% trans %}Add Layer Commands{% endtrans %}</_name> + <id>org.inkstitch.layer_commands.{{ locale }}</id> <dependency type="executable" location="extensions">inkstitch.py</dependency> <dependency type="executable" location="extensions">inkex.py</dependency> <param name="description" type="description">{% trans %}Commands will be added to the currently-selected layer.{% endtrans %}</param> {% for command, description in layer_commands %} - <param name="{{ command }}" type="boolean" gui-text="{{ _(description) }}">false</param> + <param name="{{ command }}" type="boolean" _gui-text="{{ _(description) }}">false</param> {% endfor %} <param name="extension" type="string" gui-hidden="true">layer_commands</param> <effect> <object-type>all</object-type> - <effects-menu> - <submenu name="Ink/Stitch" /> - </effects-menu> + <submenu name="Ink/Stitch"> + <submenu name="Ink/Stitch"> + <submenu name="{% trans %}English{% endtrans %}" /> + </submenu> + </submenu> </effect> <script> <command reldir="extensions" interpreter="python">inkstitch.py</command> diff --git a/templates/object_commands.inx b/templates/object_commands.inx index 71f9d0b3..024a694b 100644 --- a/templates/object_commands.inx +++ b/templates/object_commands.inx @@ -1,17 +1,19 @@ <?xml version="1.0" encoding="UTF-8"?> <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> - <name>{% trans %}Attach Commands{% endtrans %}</name> - <id>org.inkstitch.commands</id> + <name>{% trans %}Attach Commands{% endtrans %}</_name> + <id>org.inkstitch.commands.{{ locale }}</id> <dependency type="executable" location="extensions">inkstitch.py</dependency> <dependency type="executable" location="extensions">inkex.py</dependency> {% for command, description in object_commands %} - <param name="{{ object }}" type="boolean" gui-text="{{ _(description ) }}">false</param> + <param name="{{ object }}" type="boolean" _gui-text="{{ _(description ) }}">false</param> {% endfor %} <effect> <object-type>all</object-type> - <effects-menu> - <submenu name="Ink/Stitch" /> - </effects-menu> + <submenu name="Ink/Stitch"> + <submenu name="Ink/Stitch"> + <submenu name="{% trans %}English{% endtrans %}" /> + </submenu> + </submenu> </effect> <script> <command reldir="extensions" interpreter="python">inkstitch.py</command> diff --git a/templates/output.inx b/templates/output.inx index b517ea70..87befee4 100644 --- a/templates/output.inx +++ b/templates/output.inx @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> - <name>{{ format | upper }} file output</name> - <id>org.inkstitch.output.{{ format }}</id> + <name>{{ format | upper }} file output</_name> + <id>org.inkstitch.output.{{ format }}.{{ locale }}</id> <dependency type="executable" location="extensions">inkstitch.py</dependency> <dependency type="executable" location="extensions">inkex.py</dependency> <output> diff --git a/templates/params.inx b/templates/params.inx index 2397be8e..1d06e56f 100644 --- a/templates/params.inx +++ b/templates/params.inx @@ -1,14 +1,16 @@ <?xml version="1.0" encoding="UTF-8"?> <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> - <name>{% trans %}Params{% endtrans %}</name> - <id>org.inkstitch.params</id> + <name>{% trans %}Params{% endtrans %}</_name> + <id>org.inkstitch.params.{{ locale }}</id> <dependency type="executable" location="extensions">inkstitch.py</dependency> <dependency type="executable" location="extensions">inkex.py</dependency> <param name="extension" type="string" gui-hidden="true">params</param> <effect> <object-type>all</object-type> <effects-menu> - <submenu name="Ink/Stitch"/> + <submenu name="Ink/Stitch"> + <submenu name="{% trans %}English{% endtrans %}" /> + </submenu> </effects-menu> </effect> <script> diff --git a/templates/print.inx b/templates/print.inx index 2670d30e..eee9c55e 100644 --- a/templates/print.inx +++ b/templates/print.inx @@ -1,14 +1,16 @@ <?xml version="1.0" encoding="UTF-8"?> <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> - <name>{% trans %}Print{% endtrans %}</name> - <id>org.inkstitch.print</id> + <name>{% trans %}Print{% endtrans %}</_name> + <id>org.inkstitch.print.{{ locale }}</id> <dependency type="executable" location="extensions">inkstitch.py</dependency> <dependency type="executable" location="extensions">inkex.py</dependency> <param name="extension" type="string" gui-hidden="true">print</param> <effect> <object-type>all</object-type> <effects-menu> - <submenu name="Ink/Stitch"/> + <submenu name="Ink/Stitch"> + <submenu name="{% trans %}English{% endtrans %}" /> + </submenu> </effects-menu> </effect> <script> diff --git a/templates/simulate.inx b/templates/simulate.inx index 7a0174a3..4a517994 100644 --- a/templates/simulate.inx +++ b/templates/simulate.inx @@ -1,14 +1,16 @@ <?xml version="1.0" encoding="UTF-8"?> <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> - <name>{% trans %}Simulate{% endtrans %}</name> - <id>org.inkstitch.simulate</id> + <name>{% trans %}Simulate{% endtrans %}</_name> + <id>org.inkstitch.simulate.{{ locale }}</id> <dependency type="executable" location="extensions">inkstitch.py</dependency> <dependency type="executable" location="extensions">inkex.py</dependency> <param name="extension" type="string" gui-hidden="true">simulate</param> <effect> <object-type>all</object-type> <effects-menu> - <submenu name="Ink/Stitch"/> + <submenu name="Ink/Stitch"> + <submenu name="{% trans %}English{% endtrans %}" /> + </submenu> </effects-menu> </effect> <script> diff --git a/templates/zip.inx b/templates/zip.inx index 9af05ab9..bf01dea2 100644 --- a/templates/zip.inx +++ b/templates/zip.inx @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> - <name>embroidery ZIP file output</name> - <id>org.inkstitch.output.zip</id> + <name>embroidery ZIP file output</_name> + <id>org.inkstitch.output.zip.{{ locale }}</id> <dependency type="executable" location="extensions">inkstitch.py</dependency> <dependency type="executable" location="extensions">inkex.py</dependency> <output> @@ -12,7 +12,7 @@ <dataloss>true</dataloss> </output> {% for format, description in formats %} - <param name="format-{{ format }}" type="boolean" gui-text=".{{ format | upper }}: {{ _(description) }}">false</param> + <param name="format-{{ format }}" type="boolean" _gui-text=".{{ format | upper }}: {{ _(description) }}">false</param> {% endfor %} <param name="extension" type="string" gui-hidden="true">zip</param> <script> |
