qt: use delegate QTranslator to gettext (as in QML) and include Qt standard lib translations for strings
used by QTextEdit.createStandardContextMenu()
This commit is contained in:
17
electrum/gui/common_qt/i18n.py
Normal file
17
electrum/gui/common_qt/i18n.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from PyQt6.QtCore import QTranslator
|
||||
|
||||
from electrum.i18n import _
|
||||
|
||||
|
||||
class ElectrumTranslator(QTranslator):
|
||||
"""Delegator for Qt translations to gettext"""
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
# explicit enumeration of translatable strings from Qt standard library, so these
|
||||
# will be included in the electrum gettext translation template
|
||||
self._strings = [_('&Undo'), _('&Redo'), _('Cu&t'), _('&Copy'), _('&Paste'), _('Select All'),
|
||||
_('Copy &Link Location')]
|
||||
|
||||
def translate(self, context, source_text: str, disambiguation, n):
|
||||
return _(source_text, context=context)
|
||||
@@ -20,14 +20,15 @@ except Exception as e:
|
||||
"Error: Could not import PyQt6.QtQml. On Linux systems, "
|
||||
"you may try 'sudo apt-get install python3-pyqt6.qtquick'") from e
|
||||
|
||||
from PyQt6.QtCore import (Qt, QCoreApplication, QLocale, QTranslator, QTimer, QT_VERSION_STR, PYQT_VERSION_STR)
|
||||
from PyQt6.QtCore import (Qt, QCoreApplication, QLocale, QTimer, QT_VERSION_STR, PYQT_VERSION_STR)
|
||||
from PyQt6.QtGui import QGuiApplication
|
||||
|
||||
from electrum.i18n import _
|
||||
from electrum.plugin import run_hook
|
||||
from electrum.util import profiler
|
||||
from electrum.logging import Logger
|
||||
from electrum.gui import BaseElectrumGui
|
||||
from electrum.gui.common_qt.i18n import ElectrumTranslator
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from electrum.daemon import Daemon
|
||||
@@ -37,14 +38,6 @@ if TYPE_CHECKING:
|
||||
from .qeapp import ElectrumQmlApplication, Exception_Hook
|
||||
|
||||
|
||||
class ElectrumTranslator(QTranslator):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
def translate(self, context, source_text, disambiguation, n):
|
||||
return _(source_text, context=context)
|
||||
|
||||
|
||||
class ElectrumGui(BaseElectrumGui, Logger):
|
||||
@profiler
|
||||
def __init__(self, config: 'SimpleConfig', daemon: 'Daemon', plugins: 'Plugins'):
|
||||
|
||||
@@ -41,6 +41,7 @@ except Exception as e:
|
||||
from PyQt6.QtGui import QGuiApplication
|
||||
from PyQt6.QtWidgets import QApplication, QSystemTrayIcon, QWidget, QMenu, QMessageBox, QDialog
|
||||
from PyQt6.QtCore import QObject, pyqtSignal, QTimer, Qt
|
||||
|
||||
import PyQt6.QtCore as QtCore
|
||||
|
||||
try:
|
||||
@@ -72,6 +73,8 @@ from electrum.storage import WalletStorage
|
||||
from electrum.wizard import WizardViewState
|
||||
from electrum.keystore import load_keystore
|
||||
|
||||
from electrum.gui.common_qt.i18n import ElectrumTranslator
|
||||
|
||||
from .util import read_QIcon, ColorScheme, custom_message_box, MessageBoxMixin, WWLabel
|
||||
from .main_window import ElectrumWindow
|
||||
from .network_dialog import NetworkDialog
|
||||
@@ -110,7 +113,6 @@ class QElectrumApplication(QApplication):
|
||||
alias_received_signal = pyqtSignal()
|
||||
|
||||
|
||||
|
||||
class ElectrumGui(BaseElectrumGui, Logger):
|
||||
|
||||
network_dialog: Optional['NetworkDialog']
|
||||
@@ -137,6 +139,8 @@ class ElectrumGui(BaseElectrumGui, Logger):
|
||||
self.app = QElectrumApplication(sys.argv)
|
||||
self.app.installEventFilter(self.efilter)
|
||||
self.app.setWindowIcon(read_QIcon("electrum.png"))
|
||||
self.translator = ElectrumTranslator()
|
||||
self.app.installTranslator(self.translator)
|
||||
self._cleaned_up = False
|
||||
# timer
|
||||
self.timer = QTimer(self.app)
|
||||
|
||||
@@ -41,7 +41,6 @@ if TYPE_CHECKING:
|
||||
from .main_window import ElectrumWindow
|
||||
|
||||
|
||||
|
||||
class LightningTxDialog(WindowModalDialog):
|
||||
|
||||
def __init__(self, parent: 'ElectrumWindow', tx_item: dict):
|
||||
@@ -68,12 +67,13 @@ class LightningTxDialog(WindowModalDialog):
|
||||
fee_msat = tx_item['fee_msat']
|
||||
fee_sat = Decimal(fee_msat) / 1000 if fee_msat is not None else None
|
||||
fee_str = self.main_window.format_amount_and_units(fee_sat, timestamp=self.timestamp)
|
||||
vbox.addWidget(QLabel(_("Fee") + f": {fee_str}"))
|
||||
vbox.addWidget(QLabel(_("Fee: {}").format(fee_str)))
|
||||
time_str = datetime.datetime.fromtimestamp(self.timestamp).isoformat(' ')[:-3]
|
||||
vbox.addWidget(QLabel(_("Date") + ": " + time_str))
|
||||
self.tx_desc_label = QLabel(_("Description:"))
|
||||
vbox.addWidget(self.tx_desc_label)
|
||||
self.tx_desc = ButtonsLineEdit(self.label)
|
||||
|
||||
def on_edited():
|
||||
text = self.tx_desc.text()
|
||||
if self.main_window.wallet.set_label(self.payment_hash, text):
|
||||
|
||||
Reference in New Issue
Block a user