[PyQt] [PYQT5] [Pylupdate5] Bug in pylupdate5: wrong line numeration

Phil Thompson phil at riverbankcomputing.com
Tue Feb 19 11:04:41 GMT 2019


On 15 Feb 2019, at 5:04 am, ?????? ????????? <rk.hh at live.com> wrote:
> 
> Hello there,
> I discovered a bug in pylupdate5 tool.
> Through .ts file generation it sets wrong line numbers for translation strings if there are strings ending with doubled single or double quotes symbol (which is an empty string literal in python) before translated line.
> Plain example:
> 
> Python file:
> 
> import sys
> from PyQt5 import QtCore, QtWidgets
> from PyQt5.QtWidgets import QMainWindow, QLabel, QGridLayout, QWidget
> from PyQt5.QtCore import QSize
> 
> class HelloWindow(QMainWindow):
>     def __init__(self):
>         QMainWindow.__init__(self)
> 
>         self.setMinimumSize(QSize(640, 480))
>         self.setWindowTitle(self.tr("Hello world") )
> 
>         centralWidget = QWidget(self)
>         self.setCentralWidget(centralWidget)
> 
>         gridLayout = QGridLayout(self)
>         centralWidget.setLayout(gridLayout)
> 
>         self.dummyvar = ""
>         title = QLabel(self.tr("Hello World from PyQt"), self)
>         title.setAlignment(QtCore.Qt.AlignCenter)
>         gridLayout.addWidget(title, 0, 0)
> 
> if __name__ == "__main__":
>     app = QtWidgets.QApplication(sys.argv)
>     mainWin = HelloWindow()
>     mainWin.show()
>     sys.exit( app.exec_() )
> 
> 
> Resulting .ts file:
> 
> <?xml version="1.0" encoding="utf-8"?>
> <!DOCTYPE TS><TS version="2.0">
> <context>
>     <name>HelloWindow</name>
>     <message>
>         <location filename="main.py" line="11"/>
>         <source>Hello world</source>
>         <translation type="unfinished"></translation>
>     </message>
>     <message>
>         <location filename="main.py" line="21"/>
>         <source>Hello World from PyQt</source>
>         <translation type="unfinished"></translation>
>     </message>
> </context>
> </TS>
> 
> 
> We can see the string literal on line 11 is defined correctly, but a second translated string on line 20 is defined as it was on line 21 in .ts file. If we remove 19 line with empty string literal assignng (so translated string will be on line 19 instead of 20) and run pylupdate5 again, in resulting .ts file that string will have correct line number 19.

Should be fixed in tonight's PyQt snapshot.

Thanks,
Phil


More information about the PyQt mailing list