PyBitmessage-2021-04-27/src/tr.py

34 lines
970 B
Python
Raw Normal View History

2019-10-22 14:24:52 +00:00
"""
2021-03-03 16:14:16 +00:00
Slim layer providing environment agnostic _translate()
2019-10-22 14:24:52 +00:00
"""
import state
2019-10-22 14:24:52 +00:00
2021-03-03 16:14:16 +00:00
def _tr_dummy(context, text, disambiguation=None, n=None):
2020-01-15 10:47:26 +00:00
# pylint: disable=unused-argument
2021-03-03 16:14:16 +00:00
return text
2019-10-22 14:24:52 +00:00
2021-03-03 16:14:16 +00:00
if state.enableGUI and not state.curses:
try:
2019-02-11 16:48:57 +00:00
from fallback import qtpy # noqa:F401
2021-03-03 16:14:16 +00:00
from qtpy import QtWidgets, QtCore, API
except ImportError:
_translate = _tr_dummy
else:
2021-03-03 16:14:16 +00:00
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