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

33 lines
923 B
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
"""
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 qtpy import QtWidgets, QtCore, API
except ImportError:
_translate = _tr_dummy
else:
2021-03-03 17:14:16 +01: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