This version of tr._translate is probably compatible with all Qt APIs
This commit is contained in:
parent
4929a63b32
commit
81f3d366a6
46
src/tr.py
46
src/tr.py
|
@ -1,22 +1,32 @@
|
||||||
|
"""
|
||||||
|
Slim layer providing environment agnostic _translate()
|
||||||
|
"""
|
||||||
|
|
||||||
import state
|
import state
|
||||||
|
|
||||||
|
|
||||||
def _translate(context, text, disambiguation=None, n=None):
|
def _tr_dummy(context, text, disambiguation=None, n=None):
|
||||||
return translateText(context, text, n)
|
# pylint: disable=unused-argument
|
||||||
|
|
||||||
|
|
||||||
def translateText(context, text, n=None):
|
|
||||||
"""Translate text in context"""
|
|
||||||
try:
|
|
||||||
enableGUI = state.enableGUI
|
|
||||||
except AttributeError: # inside the plugin
|
|
||||||
enableGUI = True
|
|
||||||
if enableGUI:
|
|
||||||
from qtpy import QtWidgets, QtCore
|
|
||||||
if n is None:
|
|
||||||
return QtWidgets.QApplication.translate(context, text)
|
|
||||||
else:
|
|
||||||
return QtWidgets.QApplication.translate(
|
|
||||||
context, text, None, QtCore.QCoreApplication.CodecForTr, n)
|
|
||||||
else:
|
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
if state.enableGUI and not state.curses:
|
||||||
|
try:
|
||||||
|
from qtpy import QtWidgets, QtCore, API
|
||||||
|
except ImportError:
|
||||||
|
_translate = _tr_dummy
|
||||||
|
else:
|
||||||
|
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
|
||||||
|
|
Reference in New Issue
Block a user