From 2d264a57e1507059fb7e1babbdd2b6e1a61c8f80 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 1 Aug 2013 16:44:59 +0200 Subject: [PATCH] de-duplicate extra comments when adding a message multiple times Change-Id: I1ed80166be3cb53f865c083b0a693148b6000731 Reviewed-by: hjk Reviewed-by: Oswald Buddenhagen --- src/linguist/shared/translator.cpp | 12 +++++++++--- .../lupdate/testdata/good/multiple_locations/main.cpp | 5 +++++ .../testdata/good/multiple_locations/project.ts.result | 1 + 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/linguist/shared/translator.cpp b/src/linguist/shared/translator.cpp index 43d37f4..f5f4ab7 100644 --- a/src/linguist/shared/translator.cpp +++ b/src/linguist/shared/translator.cpp @@ -176,9 +176,15 @@ void Translator::extend(const TranslatorMessage &msg, ConversionData &cd) emsg.addReferenceUniq(msg.fileName(), msg.lineNumber()); if (!msg.extraComment().isEmpty()) { QString cmt = emsg.extraComment(); - if (!cmt.isEmpty()) - cmt.append(QLatin1String("\n----------\n")); - cmt.append(msg.extraComment()); + if (!cmt.isEmpty()) { + QStringList cmts = cmt.split(QLatin1String("\n----------\n")); + if (!cmts.contains(msg.extraComment())) { + cmts.append(msg.extraComment()); + cmt = cmts.join(QLatin1String("\n----------\n")); + } + } else { + cmt = msg.extraComment(); + } emsg.setExtraComment(cmt); } } diff --git a/tests/auto/linguist/lupdate/testdata/good/multiple_locations/main.cpp b/tests/auto/linguist/lupdate/testdata/good/multiple_locations/main.cpp index fa01f9d..b0fd0cb 100644 --- a/tests/auto/linguist/lupdate/testdata/good/multiple_locations/main.cpp +++ b/tests/auto/linguist/lupdate/testdata/good/multiple_locations/main.cpp @@ -68,3 +68,8 @@ QObject::tr("another message", "here with a lot of noise in the comment so it is //~ meta too-much-meta QObject::tr("another message", "here with a lot of noise in the comment so it is long enough"); + + + +//: commented +qtTrId("lollipop"); diff --git a/tests/auto/linguist/lupdate/testdata/good/multiple_locations/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/multiple_locations/project.ts.result index b0a1717..b3dde96 100644 --- a/tests/auto/linguist/lupdate/testdata/good/multiple_locations/project.ts.result +++ b/tests/auto/linguist/lupdate/testdata/good/multiple_locations/project.ts.result @@ -6,6 +6,7 @@ + this is the source text commented ---------- -- 2.7.4