make language changeable
This commit is contained in:
@@ -65,7 +65,7 @@ class AboutDialog(QDialog):
|
|||||||
<ul>
|
<ul>
|
||||||
<li>PySide6 {pyside} (LGPL v3) - <a href="https://doc.qt.io/qtforpython-6/">https://doc.qt.io/qtforpython-6/</a></li>
|
<li>PySide6 {pyside} (LGPL v3) - <a href="https://doc.qt.io/qtforpython-6/">https://doc.qt.io/qtforpython-6/</a></li>
|
||||||
<li>Qt6 {qt} (LGPL v3) - <a href="https://code.qt.io/cgit/qt/qtbase.git/">https://code.qt.io/cgit/qt/qtbase.git/</a></li>
|
<li>Qt6 {qt} (LGPL v3) - <a href="https://code.qt.io/cgit/qt/qtbase.git/">https://code.qt.io/cgit/qt/qtbase.git/</a></li>
|
||||||
<li>urllib3 (MIT) - <a href="https://urllib3.readthedocs.io/en/stable/">https://urllib3.readthedocs.io/en/stable/</a></li>
|
<li>urllib3 (MIT) - <a href="https://github.com/urllib3/urllib3">https://github.com/urllib3/urllib3</a></li>
|
||||||
<li>watchdog 2.16 (Apache 2.0) - <a href="https://github.com/gorakhargosh/watchdog">https://github.com/gorakhargosh/watchdog</a></li>
|
<li>watchdog 2.16 (Apache 2.0) - <a href="https://github.com/gorakhargosh/watchdog">https://github.com/gorakhargosh/watchdog</a></li>
|
||||||
</ul>""".format(pyside=PySide6.__version__, qt=PySide6.QtCore.__version__)
|
</ul>""".format(pyside=PySide6.__version__, qt=PySide6.QtCore.__version__)
|
||||||
label = _(textwrap.dedent(dependencies))
|
label = _(textwrap.dedent(dependencies))
|
||||||
|
|||||||
20
main.py
20
main.py
@@ -16,6 +16,8 @@ from ravenui import RavenUI
|
|||||||
|
|
||||||
import gettext
|
import gettext
|
||||||
|
|
||||||
|
from settingsstore import SettingsStore
|
||||||
|
|
||||||
gettext.install('ravenlog', 'locale')
|
gettext.install('ravenlog', 'locale')
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
@@ -43,22 +45,6 @@ if __name__ == "__main__":
|
|||||||
myappid = 'opentext.ravenlog' # arbitrary string
|
myappid = 'opentext.ravenlog' # arbitrary string
|
||||||
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
|
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.
|
# workaround to make signals work in QT apps.
|
||||||
# They do not work out of the box, because the main thread
|
# They do not work out of the box, because the main thread
|
||||||
# is running in C++ code once app.exec() is executed
|
# is running in C++ code once app.exec() is executed
|
||||||
@@ -74,8 +60,6 @@ if __name__ == "__main__":
|
|||||||
PluginRegistry.load_plugin("LogFilePlugin")
|
PluginRegistry.load_plugin("LogFilePlugin")
|
||||||
PluginRegistry.load_plugin("NotesPlugin")
|
PluginRegistry.load_plugin("NotesPlugin")
|
||||||
|
|
||||||
PluginRegistry.execute("set_translator", lambda string: translator.tr(string))
|
|
||||||
|
|
||||||
window = PluginRegistry.execute_single("create_main_window")
|
window = PluginRegistry.execute_single("create_main_window")
|
||||||
RavenUI.window = window
|
RavenUI.window = window
|
||||||
window.show()
|
window.show()
|
||||||
|
|||||||
@@ -2,7 +2,11 @@ import gettext
|
|||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from settingsstore import SettingsStore
|
||||||
|
|
||||||
|
settings = SettingsStore.load()
|
||||||
locale = os.environ['LANG'] if os.environ['LANG'] else "en"
|
locale = os.environ['LANG'] if os.environ['LANG'] else "en"
|
||||||
|
locale = settings.session.get('general', 'lang', fallback=locale)
|
||||||
|
|
||||||
_ = False
|
_ = False
|
||||||
src_dir = Path(__file__).resolve().parent.parent
|
src_dir = Path(__file__).resolve().parent.parent
|
||||||
|
|||||||
@@ -10,14 +10,20 @@ from raven.mainwindow import MainWindow
|
|||||||
from raven.pluginbase import PluginBase
|
from raven.pluginbase import PluginBase
|
||||||
from raven.plugins.domain.menucontribution import MenuContribution
|
from raven.plugins.domain.menucontribution import MenuContribution
|
||||||
from raven.plugins.domain.raction import RAction
|
from raven.plugins.domain.raction import RAction
|
||||||
|
from raven.plugins.domain.rmenu import RMenu
|
||||||
from raven.plugins.ravenlog.Tab import Tab
|
from raven.plugins.ravenlog.Tab import Tab
|
||||||
from raven.i18n import _
|
from raven.i18n import _
|
||||||
|
from settings import Settings
|
||||||
|
|
||||||
|
|
||||||
class RavenLogPlugin(PluginBase):
|
class RavenLogPlugin(PluginBase):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(RavenLogPlugin, self).__init__()
|
super(RavenLogPlugin, self).__init__()
|
||||||
self.main_window = None
|
self.main_window = None
|
||||||
|
|
||||||
|
def set_settings(self, settings: Settings):
|
||||||
|
self.settings = settings
|
||||||
|
|
||||||
def create_main_window(self):
|
def create_main_window(self):
|
||||||
if not self.main_window:
|
if not self.main_window:
|
||||||
self.main_window = MainWindow()
|
self.main_window = MainWindow()
|
||||||
@@ -27,8 +33,22 @@ class RavenLogPlugin(PluginBase):
|
|||||||
return [
|
return [
|
||||||
MenuContribution("file", action=self._action_close(), action_id="close application", after="<last>"),
|
MenuContribution("file", action=self._action_close(), action_id="close application", after="<last>"),
|
||||||
MenuContribution("help", action=self._action_about(), action_id="open about dialog", after="<last>"),
|
MenuContribution("help", action=self._action_about(), action_id="open about dialog", after="<last>"),
|
||||||
|
MenuContribution("settings", menu=self._sub_menu_languages(), action_id="recent files menu"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def _sub_menu_languages(self) -> RMenu:
|
||||||
|
menu = RMenu(_("&Languages"))
|
||||||
|
menu.add_action(RAction(_("&Default"), lambda: self._set_lang('')))
|
||||||
|
menu.add_action(RAction(_("&English"), lambda: self._set_lang('en')))
|
||||||
|
menu.add_action(RAction(_("&German"), lambda: self._set_lang('de')))
|
||||||
|
return menu
|
||||||
|
|
||||||
|
def _set_lang(self, lang: str):
|
||||||
|
if (lang == ''):
|
||||||
|
self.settings.session.remove_option('general', 'lang')
|
||||||
|
else:
|
||||||
|
self.settings.session.set('general', 'lang', lang)
|
||||||
|
|
||||||
def current_file(self) -> Optional[str]:
|
def current_file(self) -> Optional[str]:
|
||||||
return self.main_window.tabs.current_file()
|
return self.main_window.tabs.current_file()
|
||||||
|
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ class Settings():
|
|||||||
def set_session(self, section: str, option: str, value: str):
|
def set_session(self, section: str, option: str, value: str):
|
||||||
return self.session.set(section, option, value)
|
return self.session.set(section, option, value)
|
||||||
|
|
||||||
def get_session(self, section: str, option: str):
|
def get_session(self, section: str, option: str) -> str:
|
||||||
return self.session.get(section, option)
|
return self.session.get(section, option)
|
||||||
|
|
||||||
def getint_session(self, section: str, option: str):
|
def getint_session(self, section: str, option: str) -> int:
|
||||||
return self.session.getint(section, option)
|
return self.session.getint(section, option)
|
||||||
|
|
||||||
def getboolean_session(self, section: str, option: str):
|
def getboolean_session(self, section: str, option: str) -> bool:
|
||||||
return self.session.getboolean(section, option)
|
return self.session.getboolean(section, option)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user