From 512c3411648b24505165d555a04e82ba689f8aed Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sun, 19 Aug 2018 22:14:10 -0400 Subject: integrate inx generation into ink/stitch proper --- lib/inx/utils.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 lib/inx/utils.py (limited to 'lib/inx/utils.py') diff --git a/lib/inx/utils.py b/lib/inx/utils.py new file mode 100644 index 00000000..da0a4614 --- /dev/null +++ b/lib/inx/utils.py @@ -0,0 +1,26 @@ +import os +from os.path import dirname +from jinja2 import Environment, FileSystemLoader + +from ..i18n import translation as inkstitch_translation + + +_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") + +def build_environment(): + env = Environment( + loader = FileSystemLoader(template_path), + autoescape = True, + extensions=['jinja2.ext.i18n'] + ) + + env.install_gettext_translations(inkstitch_translation) + + return env + +def write_inx_file(name, contents): + inx_file_name = "inkstitch_%s.inx" % name + with open(os.path.join(inx_path, inx_file_name), 'w') as inx_file: + print >> inx_file, contents -- cgit v1.2.3 From a2cad1f522074b84895897632ac69dcb5deda340 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Mon, 20 Aug 2018 20:42:02 -0400 Subject: generate INX files for all languages --- lib/inx/utils.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'lib/inx/utils.py') 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 -- cgit v1.2.3 From 038875f876d79d0f1e971886fe42f5bee4f9f31e Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Tue, 21 Aug 2018 20:32:50 -0400 Subject: autopep8 --- lib/inx/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/inx/utils.py') diff --git a/lib/inx/utils.py b/lib/inx/utils.py index 6103f360..6670cfcb 100644 --- a/lib/inx/utils.py +++ b/lib/inx/utils.py @@ -13,10 +13,11 @@ 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), - autoescape = True, + loader=FileSystemLoader(template_path), + autoescape=True, extensions=['jinja2.ext.i18n'] ) @@ -25,11 +26,13 @@ def build_environment(): return env + def write_inx_file(name, contents): 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 -- cgit v1.2.3 From 908f2cd7727e939b87e3f57c1d3a189705de4c94 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Tue, 21 Aug 2018 21:43:09 -0400 Subject: pyflakes fixes --- lib/inx/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/inx/utils.py') diff --git a/lib/inx/utils.py b/lib/inx/utils.py index 6670cfcb..8dd3fdf8 100644 --- a/lib/inx/utils.py +++ b/lib/inx/utils.py @@ -3,7 +3,7 @@ import gettext from os.path import dirname from jinja2 import Environment, FileSystemLoader -from ..i18n import translation as default_translation, locale_dir, _, N_ +from ..i18n import translation as default_translation, locale_dir, N_ _top_path = dirname(dirname(dirname(os.path.realpath(__file__)))) -- cgit v1.2.3 From d02ddff4753f89f913613a10cfa766d86f80d9a9 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 22 Aug 2018 14:02:53 -0400 Subject: handle unicode in inx generation --- lib/inx/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/inx/utils.py') diff --git a/lib/inx/utils.py b/lib/inx/utils.py index 6103f360..cd0fdc6e 100644 --- a/lib/inx/utils.py +++ b/lib/inx/utils.py @@ -28,7 +28,7 @@ def build_environment(): def write_inx_file(name, contents): 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 + print >> inx_file.encode("utf-8"), contents def iterate_inx_locales(): global current_translation, current_locale -- cgit v1.2.3 From 674283c13557a5c0e30d7e8a2048c3297b044888 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 22 Aug 2018 14:12:39 -0400 Subject: fix missing install extension INX file --- lib/inx/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/inx/utils.py') diff --git a/lib/inx/utils.py b/lib/inx/utils.py index cd0fdc6e..7c471276 100644 --- a/lib/inx/utils.py +++ b/lib/inx/utils.py @@ -28,7 +28,7 @@ def build_environment(): def write_inx_file(name, contents): 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.encode("utf-8"), contents + print >> inx_file, contents.encode("utf-8") def iterate_inx_locales(): global current_translation, current_locale -- cgit v1.2.3