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

?????? ????????? rk.hh at live.com
Fri Feb 15 05:04:04 GMT 2019


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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190215/1d6f1328/attachment.html>


More information about the PyQt mailing list