summaryrefslogtreecommitdiff
path: root/lib/inx/utils.py
diff options
context:
space:
mode:
authorLex Neva <github.com@lexneva.name>2018-08-20 20:42:02 -0400
committerLex Neva <github.com@lexneva.name>2018-08-20 20:42:02 -0400
commita2cad1f522074b84895897632ac69dcb5deda340 (patch)
treebac168dd8ba5b70537bc4c0c1cfa9f8257855791 /lib/inx/utils.py
parent871358d990d4a06b2eaaf0e405f2d18e26753d52 (diff)
generate INX files for all languages
Diffstat (limited to 'lib/inx/utils.py')
-rw-r--r--lib/inx/utils.py29
1 files changed, 26 insertions, 3 deletions
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