i18n with gettext
This commit is contained in:
@@ -9,23 +9,20 @@ from raven.pluginbase import PluginBase
|
||||
from raven.plugins.ravenlog.Tab import Tab
|
||||
from settings import Settings
|
||||
|
||||
from raven.i18n import _
|
||||
|
||||
class LogFilePlugin(PluginBase):
|
||||
def __init__(self):
|
||||
super(LogFilePlugin, self).__init__()
|
||||
self.settings = None
|
||||
self.tr = None
|
||||
|
||||
def set_settings(self, settings: Settings):
|
||||
self.settings = settings
|
||||
|
||||
def set_translator(self, tr: Callable[[str], str]):
|
||||
self.tr = tr
|
||||
|
||||
def create_tab(self, file: str) -> Optional[Tab]:
|
||||
if not os.path.isfile(file):
|
||||
message = QMessageBox(QMessageBox.Icon.Warning, "File not found",
|
||||
"'%s' is not a file or cannot be opened" % file)
|
||||
message = QMessageBox(QMessageBox.Icon.Warning, _("File not found"),
|
||||
_("'{0}' is not a file or cannot be opened").format(file))
|
||||
message.exec()
|
||||
return None
|
||||
|
||||
|
||||
@@ -7,26 +7,22 @@ from raven.pluginregistry import PluginRegistry
|
||||
from raven.plugins.domain.menucontribution import MenuContribution
|
||||
from raven.plugins.domain.raction import RAction
|
||||
from raven.plugins.notes.noteswidget import NotesWidget
|
||||
|
||||
from raven.i18n import _
|
||||
|
||||
class NotesPlugin(PluginBase):
|
||||
|
||||
def __init__(self):
|
||||
super(NotesPlugin, self).__init__()
|
||||
self.settings = None
|
||||
self.tr = None
|
||||
self.tab_counter = 0
|
||||
|
||||
def set_translator(self, tr: Callable[[str], str]):
|
||||
self.tr = tr
|
||||
|
||||
def get_menu_contributions(self) -> [MenuContribution]:
|
||||
return [
|
||||
MenuContribution("window", action=self._add_notes_tab_action(), action_id="add notes tab", after="<last>"),
|
||||
]
|
||||
|
||||
def _add_notes_tab_action(self) -> RAction:
|
||||
open_file = RAction(self.tr("Add &Notes"), self._add_notes_tab, shortcut='Ctrl+Shift+N',
|
||||
open_file = RAction(_("Add &Notes"), self._add_notes_tab, shortcut='Ctrl+Shift+N',
|
||||
icon_from_theme="filenew")
|
||||
return open_file
|
||||
|
||||
@@ -34,5 +30,5 @@ class NotesPlugin(PluginBase):
|
||||
self.tab_counter = self.tab_counter + 1
|
||||
notes = NotesWidget(
|
||||
"notes_tab_%d" % self.tab_counter,
|
||||
self.tr("Notes %d") % self.tab_counter)
|
||||
_("Notes {0}").format(self.tab_counter))
|
||||
PluginRegistry.execute_single("add_dock", Qt.DockWidgetArea.RightDockWidgetArea, notes)
|
||||
|
||||
@@ -12,26 +12,23 @@ from raven.plugins.domain.raction import RAction
|
||||
from raven.plugins.domain.rmenu import RMenu
|
||||
from settings import Settings
|
||||
|
||||
from raven.i18n import _
|
||||
|
||||
class OpenFilePlugin(PluginBase):
|
||||
def __init__(self):
|
||||
super(OpenFilePlugin, self).__init__()
|
||||
self.settings = None
|
||||
self.tr = None
|
||||
|
||||
def set_settings(self, settings: Settings):
|
||||
self.settings = settings
|
||||
|
||||
def set_translator(self, tr: Callable[[str], str]):
|
||||
self.tr = tr
|
||||
|
||||
def _action_open_file(self) -> RAction:
|
||||
open_file = RAction(self.tr("&Open..."), self._open_file_dialog, shortcut='Ctrl+O',
|
||||
open_file = RAction(_("&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(self.tr("Open &Recent"), icon_from_theme="document-open-recent")
|
||||
self._menu_recent_files = RMenu(_("Open &Recent"), icon_from_theme="document-open-recent")
|
||||
self._update_recent_files_menu()
|
||||
return self._menu_recent_files
|
||||
|
||||
@@ -47,7 +44,7 @@ class OpenFilePlugin(PluginBase):
|
||||
|
||||
dialog = QFileDialog()
|
||||
(selected_file, _filter) = dialog.getOpenFileName(
|
||||
caption=self.tr("Open File"),
|
||||
caption=_("Open File"),
|
||||
dir=directory
|
||||
)
|
||||
# directory=directory
|
||||
|
||||
@@ -11,17 +11,13 @@ from raven.pluginbase import PluginBase
|
||||
from raven.plugins.domain.menucontribution import MenuContribution
|
||||
from raven.plugins.domain.raction import RAction
|
||||
from raven.plugins.ravenlog.Tab import Tab
|
||||
|
||||
from raven.i18n import _
|
||||
|
||||
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()
|
||||
@@ -46,7 +42,7 @@ class RavenLogPlugin(PluginBase):
|
||||
|
||||
def _action_about(self) -> RAction:
|
||||
about_action = RAction(
|
||||
self.tr("&About"),
|
||||
_("&About"),
|
||||
action=lambda: AboutDialog().exec(),
|
||||
icon_file=constants.raven_icon
|
||||
)
|
||||
@@ -54,6 +50,6 @@ class RavenLogPlugin(PluginBase):
|
||||
|
||||
def _action_close(self) -> RAction:
|
||||
icon = "close" if sys.platform == 'win32' or sys.platform == 'cygwin' else "exit"
|
||||
close_action = RAction(self.tr("E&xit"), action=lambda: self.main_window.destruct(), shortcut='Ctrl+X',
|
||||
close_action = RAction(_("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