2018-05-02 01:21:07 +00:00
|
|
|
import sys
|
|
|
|
import os
|
2018-08-21 00:42:02 +00:00
|
|
|
from os.path import dirname, realpath
|
2018-05-02 01:21:07 +00:00
|
|
|
import gettext
|
|
|
|
|
|
|
|
_ = translation = None
|
2018-08-21 00:42:02 +00:00
|
|
|
locale_dir = None
|
2018-05-02 01:21:07 +00:00
|
|
|
|
2018-08-20 19:49:19 +00:00
|
|
|
# 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 _()
|
2018-08-22 00:32:50 +00:00
|
|
|
|
|
|
|
|
2018-08-20 19:49:19 +00:00
|
|
|
def N_(message): return message
|
|
|
|
|
2018-08-22 00:32:50 +00:00
|
|
|
|
2018-08-21 00:42:02 +00:00
|
|
|
def _set_locale_dir():
|
|
|
|
global locale_dir
|
|
|
|
|
2018-05-02 01:21:07 +00:00
|
|
|
if getattr(sys, 'frozen', False):
|
|
|
|
# we are in a pyinstaller installation
|
|
|
|
locale_dir = sys._MEIPASS
|
|
|
|
else:
|
2018-08-21 00:42:02 +00:00
|
|
|
locale_dir = dirname(dirname(realpath(__file__)))
|
2018-05-02 01:21:07 +00:00
|
|
|
|
|
|
|
locale_dir = os.path.join(locale_dir, 'locales')
|
|
|
|
|
2018-08-22 00:32:50 +00:00
|
|
|
|
2018-08-21 00:42:02 +00:00
|
|
|
def localize(languages=None):
|
2018-05-02 01:21:07 +00:00
|
|
|
global translation, _
|
|
|
|
|
|
|
|
translation = gettext.translation("inkstitch", locale_dir, fallback=True)
|
|
|
|
_ = translation.gettext
|
|
|
|
|
2018-08-22 00:32:50 +00:00
|
|
|
|
2018-08-21 00:42:02 +00:00
|
|
|
_set_locale_dir()
|
2018-05-02 01:21:07 +00:00
|
|
|
localize()
|