This repository has been archived on 2024-12-06. You can view files and clone it, but cannot push or open issues or pull requests.
PyBitmessage-2024-12-06/src/tr.py

41 lines
1.1 KiB
Python
Raw Normal View History

2019-10-22 16:24:52 +02:00
"""
2021-03-03 17:14:16 +01:00
Slim layer providing environment agnostic _translate()
2019-10-22 16:24:52 +02:00
"""
try:
2021-03-04 15:15:41 +01:00
import state
except ImportError:
from . import state
2019-10-22 16:24:52 +02:00
2021-03-03 17:14:16 +01:00
def _tr_dummy(context, text, disambiguation=None, n=None):
2020-01-15 11:47:26 +01:00
# pylint: disable=unused-argument
2021-03-03 17:14:16 +01:00
return text
2019-10-22 16:24:52 +02:00
2021-03-03 17:14:16 +01:00
if state.enableGUI and not state.curses:
try:
2021-03-03 17:14:16 +01:00
from fallback import PyQt5 # noqa:F401
from PyQt5 import QtWidgets, QtCore
except ImportError:
_translate = _tr_dummy
else:
2021-03-03 17:14:16 +01:00
try:
from PyQt5 import API
except ImportError:
API = 'pyqt5'
if API == 'pyqt5':
_translate = QtWidgets.QApplication.translate
else:
def _translate(context, text, disambiguation=None, n=None):
return (
QtWidgets.QApplication.translate(
context, text, disambiguation)
if n is None else
QtWidgets.QApplication.translate(
context, text, disambiguation,
QtCore.QCoreApplication.CodecForTr, n)
)
else:
_translate = _tr_dummy