From 871358d990d4a06b2eaaf0e405f2d18e26753d52 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Mon, 20 Aug 2018 15:49:19 -0400 Subject: gettextify INX templates --- lib/i18n.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/i18n.py') diff --git a/lib/i18n.py b/lib/i18n.py index d20f5d2f..06e0dd49 100644 --- a/lib/i18n.py +++ b/lib/i18n.py @@ -4,6 +4,11 @@ import gettext _ = translation = 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(): if getattr(sys, 'frozen', False): # we are in a pyinstaller installation -- 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/i18n.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/i18n.py') 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() -- 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/i18n.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/i18n.py') diff --git a/lib/i18n.py b/lib/i18n.py index 419c03dc..045fa1b2 100644 --- a/lib/i18n.py +++ b/lib/i18n.py @@ -9,8 +9,11 @@ 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 _set_locale_dir(): global locale_dir @@ -22,11 +25,13 @@ def _set_locale_dir(): 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() -- cgit v1.2.3