diff options
| author | Lex Neva <lexelby@users.noreply.github.com> | 2018-08-21 16:45:13 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-08-21 16:45:13 -0400 |
| commit | afb886cbe04d19c6b7d1886dfc2c6052646a2dbf (patch) | |
| tree | 2d0a6fe95a26d5b934fe893f3d2b3e94b2aadcc8 /lib/i18n.py | |
| parent | 8116f32068a4fe55e7f30ca2a369b2443d89b560 (diff) | |
| parent | 8f700007fc7d3b7866d4e4a3dac6a36bb3e1be2a (diff) | |
Merge pull request #286 from inkstitch/lexelby/i18n-revamp
localize INX files
Diffstat (limited to 'lib/i18n.py')
| -rw-r--r-- | lib/i18n.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/i18n.py b/lib/i18n.py index d20f5d2f..419c03dc 100644 --- a/lib/i18n.py +++ b/lib/i18n.py @@ -1,21 +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 _set_locale_dir(): + global locale_dir -def localize(): 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() |
