Skip to content

Commit 1ef8715

Browse files
committed
Call Qt's locale and setup gettext a bit later in the game.
1 parent 50d5596 commit 1ef8715

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

mu/__init__.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
import gettext
2-
import os
2+
from os import path
33

44
from PyQt5.Qt import QLocale
55

6-
# Configure locale and language
7-
# Define where the translation assets are to be found.
8-
localedir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'locale'))
9-
language_code = QLocale.system().name()
10-
# DEBUG/TRANSLATE: override the language code here (e.g. to Chinese).
11-
# language_code = 'zh'
12-
gettext.translation('mu', localedir=localedir,
13-
languages=[language_code], fallback=True).install()
6+
7+
def setup_gettext():
8+
"""
9+
Sets up gettext translations, installing the global _() function.
10+
"""
11+
# Where the translation assets are to be found.
12+
localedir = path.abspath(path.join(path.dirname(__file__), 'locale'))
13+
14+
# Ask Qt for system language: returns an 'll_CC' string, where 'll' is a
15+
# 2-letter ISO 639 language, and CC is a 2/3-letter ISO 3166 country code.
16+
# DEBUG/TRANSLATE: Override with the LANG environment variable.
17+
language_code = QLocale.system().name()
18+
19+
# Install the _() translation function.
20+
gettext.translation('mu', localedir=localedir,
21+
languages=[language_code], fallback=True).install()
22+
1423

1524
__version__ = '1.0.2'

mu/app.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828

2929
from PyQt5.QtCore import QTimer, Qt
3030
from PyQt5.QtWidgets import QApplication, QSplashScreen
31+
from PyQt5.Qt import QLocale
3132

32-
from mu import __version__, language_code
33+
from mu import __version__
3334
from mu.logic import Editor, LOG_FILE, LOG_DIR, DEBUGGER_PORT, ENCODING
3435
from mu.interface import Window
3536
from mu.resources import load_pixmap, load_icon
@@ -111,7 +112,7 @@ def run():
111112
logging.info('\n\n-----------------\n\nStarting Mu {}'.format(__version__))
112113
logging.info(platform.uname())
113114
logging.info('Python path: {}'.format(sys.path))
114-
logging.info('Language code: {}'.format(language_code))
115+
logging.info('Language code: {}'.format(QLocale.system().name()))
115116

116117
# The app object is the application running on your computer.
117118
app = QApplication(sys.argv)

mu/logic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@
3838
from pycodestyle import StyleGuide, Checker
3939
from mu.resources import path
4040
from mu.debugger.utils import is_breakpoint_line
41-
from mu import __version__
41+
from mu import __version__, setup_gettext
4242

43+
setup_gettext()
4344

4445
# The user's home directory.
4546
HOME_DIRECTORY = os.path.expanduser('~')

0 commit comments

Comments
 (0)