8000 fix translate arguments by jdorr · Pull Request #382 · mottosso/Qt.py · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix translate arguments #382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 27 additions & 14 deletions Qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,23 +831,35 @@ def _translate(context, sourceText, *args):
# The first argument is disambiguation[str]
# The last argument is n[int]
# The middle argument can be encoding[QtCore.QCoreApplication.Encoding]
try:
app = Qt.QtCore.QCoreApplication
except AttributeError:
raise NotImplementedError(
"Missing QCoreApplication implementation for {}".format(
Qt.__binding__
)
)

def get_arg(index):
try:
return args[index]
except IndexError:
pass

n = -1
encoding = None

if len(args) == 3:
disambiguation, encoding, n = args
elif len(args) == 2:
disambiguation, n = args
encoding = None
else:
raise TypeError(
"Expected 4 or 5 arguments, got {0}.".format(len(args) + 2))
disambiguation = get_arg(0)
n_or_encoding = get_arg(1)

if isinstance(n_or_encoding, int):
n = n_or_encoding
else:
encoding = n_or_encoding

if hasattr(Qt.QtCore, "QCoreApplication"):
app = getattr(Qt.QtCore, "QCoreApplication")
else:
raise NotImplementedError(
"Missing QCoreApplication implementation for {binding}".format(
binding=Qt.__binding__,
)
)
if Qt.__binding__ in ("PySide2", "PyQt5"):
sanitized_args = [context, sourceText, disambiguation, n]
else:
Expand All @@ -856,8 +868,9 @@ def _translate(context, sourceText, *args):
sourceText,
disambiguation,
encoding or app.CodecForTr,
n
n,
]

return app.translate(*sanitized_args)


Expand Down
0