i18n with QT
This commit is contained in:
@@ -35,7 +35,7 @@ class MainWindow(QMainWindow):
|
||||
self.settings = SettingsStore.load()
|
||||
PluginRegistry.execute("set_settings", self.settings)
|
||||
|
||||
PluginRegistry.execute("set_translator", self.tr)
|
||||
|
||||
|
||||
self.setWindowTitle(self.tr("RavenLog"))
|
||||
self._restore_window()
|
||||
@@ -80,7 +80,7 @@ class MainWindow(QMainWindow):
|
||||
action = self._raction_to_qaction(menu_contribution.action, menu)
|
||||
menu.addAction(action)
|
||||
if menu_contribution.menu:
|
||||
submenu = QMenu(self.tr(menu_contribution.menu.label), menu_bar)
|
||||
submenu = QMenu(menu_contribution.menu.label, menu_bar)
|
||||
submenu.setIcon(QIcon.fromTheme(menu_contribution.menu.icon_from_theme))
|
||||
menu_contribution.menu.add_change_listener(
|
||||
lambda qmenu=submenu, rmenu=menu_contribution.menu: self._rmenu_update(qmenu, rmenu))
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
from PySide6.QtCore import QObject
|
||||
|
||||
|
||||
class PluginBase():
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@@ -26,7 +26,7 @@ class NotesPlugin(PluginBase):
|
||||
]
|
||||
|
||||
def _add_notes_tab_action(self) -> RAction:
|
||||
open_file = RAction("Add &Notes", self._add_notes_tab, shortcut='Ctrl+Shift+N',
|
||||
open_file = RAction(self.tr("Add &Notes"), self._add_notes_tab, shortcut='Ctrl+Shift+N',
|
||||
icon_from_theme="filenew")
|
||||
return open_file
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import os
|
||||
from typing import Callable
|
||||
from pathlib import Path
|
||||
|
||||
from PySide6.QtCore import QObject
|
||||
from PySide6.QtWidgets import QFileDialog
|
||||
|
||||
from raven.pluginbase import PluginBase
|
||||
@@ -24,12 +26,12 @@ class OpenFilePlugin(PluginBase):
|
||||
self.tr = tr
|
||||
|
||||
def _action_open_file(self) -> RAction:
|
||||
open_file = RAction("&Open...", self._open_file_dialog, shortcut='Ctrl+O',
|
||||
open_file = RAction(self.tr("&Open..."), self._open_file_dialog, shortcut='Ctrl+O',
|
||||
icon_from_theme="document-open")
|
||||
return open_file
|
||||
|
||||
def _sub_menu_recent_files(self) -> RMenu:
|
||||
self._menu_recent_files = RMenu("Open &Recent", icon_from_theme="document-open-recent")
|
||||
self._menu_recent_files = RMenu(self.tr("Open &Recent"), icon_from_theme="document-open-recent")
|
||||
self._update_recent_files_menu()
|
||||
return self._menu_recent_files
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import sys
|
||||
from typing import Optional
|
||||
from typing import Optional, Callable
|
||||
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtWidgets import QDockWidget
|
||||
@@ -16,8 +16,12 @@ from raven.plugins.ravenlog.Tab import Tab
|
||||
class RavenLogPlugin(PluginBase):
|
||||
def __init__(self):
|
||||
super(RavenLogPlugin, self).__init__()
|
||||
self.tr = None
|
||||
self.main_window = None
|
||||
|
||||
def set_translator(self, tr: Callable[[str], str]):
|
||||
self.tr = tr
|
||||
|
||||
def create_main_window(self):
|
||||
if not self.main_window:
|
||||
self.main_window = MainWindow()
|
||||
@@ -42,7 +46,7 @@ class RavenLogPlugin(PluginBase):
|
||||
|
||||
def _action_about(self) -> RAction:
|
||||
about_action = RAction(
|
||||
"&About",
|
||||
self.tr("&About"),
|
||||
action=lambda: AboutDialog().exec(),
|
||||
icon_file=constants.raven_icon
|
||||
)
|
||||
@@ -50,6 +54,6 @@ class RavenLogPlugin(PluginBase):
|
||||
|
||||
def _action_close(self) -> RAction:
|
||||
icon = "close" if sys.platform == 'win32' or sys.platform == 'cygwin' else "exit"
|
||||
close_action = RAction("E&xit", action=lambda: self.main_window.destruct(), shortcut='Ctrl+X',
|
||||
close_action = RAction(self.tr("E&xit"), action=lambda: self.main_window.destruct(), shortcut='Ctrl+X',
|
||||
icon_from_theme=icon)
|
||||
return close_action
|
||||
|
||||
Reference in New Issue
Block a user