make language changeable
This commit is contained in:
@@ -2,7 +2,11 @@ import gettext
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from settingsstore import SettingsStore
|
||||
|
||||
settings = SettingsStore.load()
|
||||
locale = os.environ['LANG'] if os.environ['LANG'] else "en"
|
||||
locale = settings.session.get('general', 'lang', fallback=locale)
|
||||
|
||||
_ = False
|
||||
src_dir = Path(__file__).resolve().parent.parent
|
||||
|
||||
@@ -10,14 +10,20 @@ from raven.mainwindow import MainWindow
|
||||
from raven.pluginbase import PluginBase
|
||||
from raven.plugins.domain.menucontribution import MenuContribution
|
||||
from raven.plugins.domain.raction import RAction
|
||||
from raven.plugins.domain.rmenu import RMenu
|
||||
from raven.plugins.ravenlog.Tab import Tab
|
||||
from raven.i18n import _
|
||||
from settings import Settings
|
||||
|
||||
|
||||
class RavenLogPlugin(PluginBase):
|
||||
def __init__(self):
|
||||
super(RavenLogPlugin, self).__init__()
|
||||
self.main_window = None
|
||||
|
||||
def set_settings(self, settings: Settings):
|
||||
self.settings = settings
|
||||
|
||||
def create_main_window(self):
|
||||
if not self.main_window:
|
||||
self.main_window = MainWindow()
|
||||
@@ -27,8 +33,22 @@ class RavenLogPlugin(PluginBase):
|
||||
return [
|
||||
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("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]:
|
||||
return self.main_window.tabs.current_file()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user