2018-08-20 02:14:10 +00:00
|
|
|
import os
|
2018-08-21 00:42:02 +00:00
|
|
|
import gettext
|
2018-08-20 02:14:10 +00:00
|
|
|
from os.path import dirname
|
|
|
|
from jinja2 import Environment, FileSystemLoader
|
|
|
|
|
2018-08-21 00:42:02 +00:00
|
|
|
from ..i18n import translation as default_translation, locale_dir, _, N_
|
2018-08-20 02:14:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
_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")
|
|
|
|
|
2018-08-21 00:42:02 +00:00
|
|
|
current_translation = default_translation
|
|
|
|
current_locale = "en_US"
|
|
|
|
|
2018-08-22 00:32:50 +00:00
|
|
|
|
2018-08-20 02:14:10 +00:00
|
|
|
def build_environment():
|
|
|
|
env = Environment(
|
2018-08-22 00:32:50 +00:00
|
|
|
loader=FileSystemLoader(template_path),
|
|
|
|
autoescape=True,
|
2018-08-20 02:14:10 +00:00
|
|
|
extensions=['jinja2.ext.i18n']
|
|
|
|
)
|
|
|
|
|
2018-08-21 00:42:02 +00:00
|
|
|
env.install_gettext_translations(current_translation)
|
|
|
|
env.globals["locale"] = current_locale
|
2018-08-20 02:14:10 +00:00
|
|
|
|
|
|
|
return env
|
|
|
|
|
2018-08-22 00:32:50 +00:00
|
|
|
|
2018-08-20 02:14:10 +00:00
|
|
|
def write_inx_file(name, contents):
|
2018-08-21 00:42:02 +00:00
|
|
|
inx_file_name = "inkstitch_%s_%s.inx" % (name, current_locale)
|
2018-08-20 02:14:10 +00:00
|
|
|
with open(os.path.join(inx_path, inx_file_name), 'w') as inx_file:
|
|
|
|
print >> inx_file, contents
|
2018-08-21 00:42:02 +00:00
|
|
|
|
2018-08-22 00:32:50 +00:00
|
|
|
|
2018-08-21 00:42:02 +00:00
|
|
|
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
|