Issue with translation detected by pylupdate6

Phil Thompson phil at riverbankcomputing.com
Sat Jun 22 14:38:07 BST 2024


On 19/06/2024 15:51, Juan José Gómez Romera wrote:
> 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

Works fine for me.  Attached is the output I get of running...

pylupdate6 --ts test.ts translated_library.py

Phil
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.ts
Type: text/xml
Size: 850 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20240622/d498101a/attachment.xml>


More information about the PyQt mailing list