make language changeable

This commit is contained in:
2022-02-02 20:04:50 +01:00
parent 9c28a41904
commit 2d21de0e43
5 changed files with 30 additions and 22 deletions

20
main.py
View File

@@ -16,6 +16,8 @@ from ravenui import RavenUI
import gettext
from settingsstore import SettingsStore
gettext.install('ravenlog', 'locale')
logging.basicConfig(level=logging.INFO)
@@ -43,22 +45,6 @@ if __name__ == "__main__":
myappid = 'opentext.ravenlog' # arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
locale = os.environ['LANG'] if os.environ['LANG'] else "en"
src_dir = Path(__file__).resolve().parent
try:
translation = gettext.translation('messages', localedir=src_dir / 'locales', languages=[locale])
if translation:
translation.install()
_ = translation.gettext
ngettext = translation.ngettext
except FileNotFoundError:
pass
if not _:
_ = gettext.gettext
ngettext = gettext.ngettext
print('No translation found')
# workaround to make signals work in QT apps.
# They do not work out of the box, because the main thread
# is running in C++ code once app.exec() is executed
@@ -74,8 +60,6 @@ if __name__ == "__main__":
PluginRegistry.load_plugin("LogFilePlugin")
PluginRegistry.load_plugin("NotesPlugin")
PluginRegistry.execute("set_translator", lambda string: translator.tr(string))
window = PluginRegistry.execute_single("create_main_window")
RavenUI.window = window
window.show()