Skip to content

Commit ea2eae8

Browse files
authored
Merge pull request #156 from abstractfactory/fix154
Fix #154
2 parents 4f8951c + 7c9e3fd commit ea2eae8

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

Qt.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
self.__modified__ = list() # Existing members modified in some way
7070

7171
# Below members are set dynamically on import relative the original binding.
72-
self.__version__ = "0.6.3"
72+
self.__version__ = "0.6.4"
7373
self.__qt_version__ = "0.0.0"
7474
self.__binding__ = "None"
7575
self.__binding_version__ = "0.0.0"
@@ -223,7 +223,7 @@ def _pyqt4():
223223
QtCore.QCoreApplication.translate(context,
224224
sourceText,
225225
disambiguation,
226-
None,
226+
QtCore.QCoreApplication.CodecForTr,
227227
n))
228228

229229
_maintain_backwards_compatibility(PyQt4)
@@ -243,13 +243,7 @@ def _pyside2():
243243
_add(QtCompat, "setSectionResizeMode",
244244
QtWidgets.QHeaderView.setSectionResizeMode)
245245

246-
_add(QtCompat, "translate",
247-
lambda context, sourceText, disambiguation, n:
248-
QtCore.QCoreApplication.translate(context,
249-
sourceText,
250-
disambiguation,
251-
None,
252-
n))
246+
_add(QtCompat, "translate", QtCore.QCoreApplication.translate)
253247

254248
_maintain_backwards_compatibility(PySide2)
255249

@@ -285,7 +279,7 @@ def _pyside():
285279
QtCore.QCoreApplication.translate(context,
286280
sourceText,
287281
disambiguation,
288-
None,
282+
QtCore.QCoreApplication.CodecForTr,
289283
n))
290284

291285
_maintain_backwards_compatibility(PySide)

tests.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,25 @@ def test_import_from_qtwidgets():
307307
assert QPushButton.__name__ == "QPushButton", QPushButton
308308

309309

310+
def test_translate_arguments():
311+
"""Arguments of QtCompat.translate are correct
312+
313+
QtCompat.translate is a shim over the PySide, PyQt4 and PyQt5
314+
equivalent with an interface like the one found in PySide2.
315+
316+
Reference: https://doc.qt.io/qt-5/qcoreapplication.html#translate
317+
"""
318+
319+
import Qt
320+
321+
# This will run on each binding
322+
result = Qt.QtCompat.translate("CustomDialog", # context
323+
"Status", # sourceText
324+
None, # disambiguation
325+
-1) # n
326+
assert result == u'Status', result
327+
328+
310329
if binding("PyQt4"):
311330
def test_preferred_pyqt4():
312331
"""QT_PREFERRED_BINDING = PyQt4 properly forces the binding"""

0 commit comments

Comments
 (0)