Issue with translation detected by pylupdate6

Juan José Gómez Romera jjgomera at gmail.com
Wed Jun 19 15:51:41 BST 2024


I have a application with international support. This application is a
python graphical interface with class derived of QObject, and other without
no qt inheritance. The application can use pyqt5 or pyqt6 indistinctly. The
problem is pylupdate6 is unable to detect fine the text using the
QtWidget.QApplication.translate short name... I post a minimum example

qt.py

> #!/usr/bin/python3
> # -*- coding: utf-8 -*-
>
> try:
>     from PyQt6 import QtWidgets
> except ImportError:
>     from PyQt5 import QtWidgets
>
> # short name used in non QObject instances to apply translation
> tr = QtWidgets.QApplication.translate
>

translated_library.py

> #!/usr/bin/python3
> # -*- coding: utf-8 -*-
>
> from qt import QtWidgets, tr
>
> class TranslatedClass():
>     title = tr("context", "This is the text to translate, not the comment")
>     name = QtWidgets.QApplication.translate("context", "This text is
> detected fine by pylupdate6")
>
> class QtRelatedClass(QtWidgets.QDialog):
>     """Its translation are correctly detect by pylupdate6"""
>     def __init__(self):
>         super().__init__(self)
>         self.name = self.tr("correctly translated text")
>

The example_es.ts is the generated ts file by pylupdate, where the title
attribute in non qt class are not fine detected.

Name attribute is detected fine, but i would use a short alias to avoid
write so long QtWidgets.QApplication.translate...

Thanks for your help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20240619/13f2219a/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: translated_library.py
Type: text/x-python
Size: 490 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20240619/13f2219a/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt.py
Type: text/x-python
Size: 240 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20240619/13f2219a/attachment-0001.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: example_es.ts
Type: text/vnd.trolltech.linguist
Size: 539 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20240619/13f2219a/attachment.ts>


More information about the PyQt mailing list