[Draft] Remove obsolete decode code (#9106)

This commit is contained in:
Roy-043
2023-03-28 21:03:33 +02:00
committed by GitHub
parent d65b05c3df
commit 87b0893044
7 changed files with 12 additions and 201 deletions

View File

@@ -43,7 +43,7 @@ except AttributeError:
_encoding = None
def translate(context, text, utf8_decode=False):
def translate(context, text):
r"""Translate the text using the Qt translate function.
It wraps around `QtGui.QApplication.translate`,
@@ -61,53 +61,24 @@ def translate(context, text, utf8_decode=False):
text: str
Text that will be translated. It could be a single word,
a full sentence, paragraph, or multiple paragraphs with new lines.
Usually the last endline character '\\n'
Usually the last endline character '\n'
that finishes the string doesn't need to be included
for translation.
utf8_decode: bool
It defaults to `False`.
This must be set to `True` to indicate that the `text`
is an `'utf8'` encoded string, so it should be returned as such.
This option is ignored when using Python 3
as with Python 3 all strings are `'utf8'` by default.
Returns
-------
str
A unicode string returned by `QtGui.QApplication.translate`.
If `utf8_decode` is `True`, the resulting string will be encoded
in `'utf8'`, and a `bytes` object will be returned.
::
Qtranslate = QtGui.QApplication.translate
return Qtranslate(context, text, None).encode("utf8")
Unicode strings
---------------
Whether it is Qt4 or Qt5, the `translate` function
always returns a unicode string.
The difference is how it handles the input.
Reference: https://pyside.github.io/docs/pyside/PySide/QtCore/
In Qt4 the translate function has a 4th parameter to define the encoding
of the input string.
>>> QtCore.QCoreApplication.translate(context, text, None, UnicodeUT8)
>>> QtGui.QApplication.translate(context, text, None, UnicodeUT8)
Reference: https://doc.qt.io/qtforpython/PySide2/QtCore
In Qt5 the strings are always assumed unicode, so the 4th parameter
is for a different use, and it is not used.
In Qt5 the strings are always assumed unicode
>>> QtCore.QCoreApplication.translate(context, text, None)
>>> QtGui.QApplication.translate(context, text, None)
"""
# Python 3 and Qt5
# The text is a utf8 string, and since it is Qt5
# the translate function doesn't use the 4th parameter
return Qtranslate(context, text, None)