diff options
| author | Lex Neva <github.com@lexneva.name> | 2018-08-25 11:47:48 -0400 |
|---|---|---|
| committer | Lex Neva <github.com@lexneva.name> | 2018-08-25 11:47:48 -0400 |
| commit | 11d3cea80caeb9738a2eb02473801487c2acba3b (patch) | |
| tree | 13510f23e5041628ef96997f14d852482ff04000 /lib/i18n.py | |
| parent | c5bd1878846c17309c99ad7554d4645088de9629 (diff) | |
| parent | 6a16e90081e619eac5921bd8614c0c46dc83f852 (diff) | |
Merge remote-tracking branch 'origin/master' into simulator-timeline
Diffstat (limited to 'lib/i18n.py')
| -rw-r--r-- | lib/i18n.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/i18n.py b/lib/i18n.py index d20f5d2f..045fa1b2 100644 --- a/lib/i18n.py +++ b/lib/i18n.py @@ -1,21 +1,37 @@ 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() |
