|
6 | 6 | #include "lupdate.h"
|
7 | 7 |
|
8 | 8 | #include <QtCore/qhash.h>
|
| 9 | +#include <QtCore/qlist.h> |
9 | 10 | #include <QtCore/qstring.h>
|
10 | 11 | #include <QtCore/qtextstream.h>
|
11 | 12 | #include <QtCore/qstack.h>
|
@@ -53,8 +54,15 @@ static int yyParenDepth;
|
53 | 54 | static int yyLineNo;
|
54 | 55 | static int yyCurLineNo;
|
55 | 56 |
|
56 |
| -static QByteArray extraComment; |
57 |
| -static QByteArray id; |
| 57 | +struct ExtraComment |
| 58 | +{ |
| 59 | + QByteArray extraComment; |
| 60 | + int lineNo; |
| 61 | +}; |
| 62 | + |
| 63 | +static QList<ExtraComment> extraComments; |
| 64 | + |
| 65 | +static QList<ExtraComment> ids; |
58 | 66 |
|
59 | 67 | QHash<QByteArray, Token> tokens = {
|
60 | 68 | {"None", Tok_None},
|
@@ -302,10 +310,10 @@ static Token getToken(StringType stringType = StringType::NoString)
|
302 | 310 | case '#':
|
303 | 311 | switch (getChar()) {
|
304 | 312 | case ':':
|
305 |
| - extraComment = readLine().trimmed(); |
| 313 | + extraComments.append({readLine().trimmed(), yyCurLineNo}); |
306 | 314 | break;
|
307 | 315 | case '=':
|
308 |
| - id = readLine().trimmed(); |
| 316 | + ids.append({readLine().trimmed(), yyCurLineNo}); |
309 | 317 | break;
|
310 | 318 | case EOF:
|
311 | 319 | return Tok_Eof;
|
@@ -583,16 +591,24 @@ static bool parseTranslate(QByteArray *text, QByteArray *context, QByteArray *co
|
583 | 591 | return false;
|
584 | 592 | }
|
585 | 593 |
|
586 |
| -static inline void setMessageParameters(TranslatorMessage *message) |
| 594 | +static void setMessageParameters(TranslatorMessage *message, |
| 595 | + int lineNo) |
587 | 596 | {
|
588 |
| - if (!extraComment.isEmpty()) { |
589 |
| - message->setExtraComment(QString::fromUtf8(extraComment)); |
590 |
| - extraComment.clear(); |
591 |
| - } |
592 |
| - if (!id.isEmpty()) { |
593 |
| - message->setId(QString::fromUtf8(id)); |
594 |
| - id.clear(); |
| 597 | + // PYSIDE-2863: parseTranslate() can read past the message |
| 598 | + // and capture extraComments intended for the next message. |
| 599 | + // Use only extraComments for the current message. |
| 600 | + QByteArray extraComment; |
| 601 | + while (!extraComments.isEmpty() && extraComments.constFirst().lineNo <= lineNo) { |
| 602 | + if (!extraComment.isEmpty()) |
| 603 | + extraComment += ' '; |
| 604 | + extraComment += extraComments.takeFirst().extraComment; |
595 | 605 | }
|
| 606 | + |
| 607 | + if (!extraComment.isEmpty()) |
| 608 | + message->setExtraComment(QString::fromUtf8(extraComment)); |
| 609 | + |
| 610 | + while (!ids.isEmpty() && ids.constFirst().lineNo <= lineNo) |
| 611 | + message->setId(QString::fromUtf8(ids.takeFirst().extraComment)); |
596 | 612 | }
|
597 | 613 |
|
598 | 614 | static void parse(Translator &tor, ConversionData &cd,
|
@@ -635,9 +651,10 @@ static void parse(Translator &tor, ConversionData &cd,
|
635 | 651 | yyTok = getToken();
|
636 | 652 | break;
|
637 | 653 | case Tok_tr:
|
638 |
| - case Tok_trUtf8: |
| 654 | + case Tok_trUtf8: { |
639 | 655 | utf8 = true;
|
640 | 656 | yyTok = getToken();
|
| 657 | + const int lineNo = yyCurLineNo; |
641 | 658 | if (match(Tok_LeftParen) && matchString(&text)) {
|
642 | 659 | comment.clear();
|
643 | 660 | bool plural = false;
|
@@ -670,21 +687,23 @@ static void parse(Translator &tor, ConversionData &cd,
|
670 | 687 | QString::fromUtf8(comment),
|
671 | 688 | {}, yyFileName, yyLineNo,
|
672 | 689 | {}, TranslatorMessage::Unfinished, plural);
|
673 |
| - setMessageParameters(&message); |
| 690 | + setMessageParameters(&message, lineNo); |
674 | 691 | tor.extend(message, cd);
|
675 | 692 | }
|
676 | 693 | }
|
| 694 | + } |
677 | 695 | break;
|
678 | 696 | case Tok_translate: {
|
679 | 697 | bool plural{};
|
| 698 | + const int lineNo = yyCurLineNo; |
680 | 699 | if (parseTranslate(&text, &context, &comment, &utf8, &plural)
|
681 | 700 | && !text.isEmpty()) {
|
682 | 701 | TranslatorMessage message(QString::fromUtf8(context),
|
683 | 702 | QString::fromUtf8(text),
|
684 | 703 | QString::fromUtf8(comment),
|
685 | 704 | {}, yyFileName, yyLineNo,
|
686 | 705 | {}, TranslatorMessage::Unfinished, plural);
|
687 |
| - setMessageParameters(&message); |
| 706 | + setMessageParameters(&message, lineNo); |
688 | 707 | tor.extend(message, cd);
|
689 | 708 | }
|
690 | 709 | }
|
|
0 commit comments