summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-08-30 15:13:46 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-08-30 15:20:14 (GMT)
commitd1a588512cec7d5fea8ee53b9c0f102d27d1e687 (patch)
tree624ba87e14af1bc4e8c592b098a9891cd9a77ccf
parentd686a95ed54b19336affc14c9222de54c9af0e72 (diff)
downloadQt-d1a588512cec7d5fea8ee53b9c0f102d27d1e687.zip
Qt-d1a588512cec7d5fea8ee53b9c0f102d27d1e687.tar.gz
Qt-d1a588512cec7d5fea8ee53b9c0f102d27d1e687.tar.bz2
preserve non-standard source references
the PO format doc suggests that all references are in filename:linennumber format, but some tools seem to deviate from that. so do our best to preserve such references, even if we can't do anything with them. Task-number: QTBUG-9488
-rw-r--r--tests/auto/linguist/lconvert/data/test-refs.po23
-rw-r--r--tests/auto/linguist/lconvert/tst_lconvert.cpp2
-rw-r--r--tools/linguist/shared/po.cpp24
3 files changed, 45 insertions, 4 deletions
diff --git a/tests/auto/linguist/lconvert/data/test-refs.po b/tests/auto/linguist/lconvert/data/test-refs.po
new file mode 100644
index 0000000..e149a38
--- /dev/null
+++ b/tests/auto/linguist/lconvert/data/test-refs.po
@@ -0,0 +1,23 @@
+msgid ""
+msgstr ""
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+"X-Language: de_DE\n"
+
+#: themer/kdmlabel.cpp:285
+#, no-c-format
+msgctxt "date format"
+msgid "%a %d %B"
+msgstr "%a %d %B"
+
+#: foo.bar.baz
+#, no-c-format
+msgid "full java class name"
+msgstr ""
+
+#: foo.car:123 monks:here file/gar.c:17:19 no:monks:here
+#, no-c-format
+msgid "some excessive locations"
+msgstr ""
diff --git a/tests/auto/linguist/lconvert/tst_lconvert.cpp b/tests/auto/linguist/lconvert/tst_lconvert.cpp
index 998f588..a3c29d8 100644
--- a/tests/auto/linguist/lconvert/tst_lconvert.cpp
+++ b/tests/auto/linguist/lconvert/tst_lconvert.cpp
@@ -317,6 +317,8 @@ void tst_lconvert::roundtrips_data()
QTest::newRow("po-xliff-po (plural-2)") << "plural-2.po" << poXlfPo << noArgs;
QTest::newRow("po-xliff-po (plural-3)") << "plural-3.po" << poXlfPo << noArgs;
+ QTest::newRow("po-ts-po (references)") << "test-refs.po" << poTsPo << noArgs;
+
QTest::newRow("ts20-ts11-ts20 (utf8)") << "codec-utf8.ts" << tsTs11Ts << noArgs;
QTest::newRow("ts20-ts11-ts20 (cp1252)") << "codec-cp1252.ts" << tsTs11Ts << noArgs;
QTest::newRow("ts20-ts11-ts20 (dual-encoding)") << "dual-encoding.ts" << tsTs11Ts << noArgs;
diff --git a/tools/linguist/shared/po.cpp b/tools/linguist/shared/po.cpp
index a58a0bf..3fd05ee 100644
--- a/tools/linguist/shared/po.cpp
+++ b/tools/linguist/shared/po.cpp
@@ -553,13 +553,26 @@ bool loadPO(Translator &translator, QIODevice &dev, ConversionData &cd)
TranslatorMessage msg;
msg.setContext(codec->toUnicode(item.context));
if (!item.references.isEmpty()) {
+ QString xrefs;
foreach (const QString &ref,
codec->toUnicode(item.references).split(
QRegExp(QLatin1String("\\s")), QString::SkipEmptyParts)) {
- int pos = ref.lastIndexOf(QLatin1Char(':'));
- if (pos != -1)
- msg.addReference(ref.left(pos), ref.mid(pos + 1).toInt());
+ int pos = ref.indexOf(QLatin1Char(':'));
+ int lpos = ref.lastIndexOf(QLatin1Char(':'));
+ if (pos != -1 && pos == lpos) {
+ bool ok;
+ int lno = ref.mid(pos + 1).toInt(&ok);
+ if (ok) {
+ msg.addReference(ref.left(pos), lno);
+ continue;
+ }
+ }
+ if (!xrefs.isEmpty())
+ xrefs += QLatin1Char(' ');
+ xrefs += ref;
}
+ if (!xrefs.isEmpty())
+ item.extra[QLatin1String("po-references")] = xrefs;
}
msg.setId(codec->toUnicode(item.id));
msg.setSourceText(codec->toUnicode(item.msgId));
@@ -771,11 +784,14 @@ bool savePO(const Translator &translator, QIODevice &dev, ConversionData &cd)
if (!msg.id().isEmpty())
out << QLatin1String("#. ts-id ") << msg.id() << '\n';
- if (!msg.fileName().isEmpty()) {
+ QString xrefs = msg.extra(QLatin1String("po-references"));
+ if (!msg.fileName().isEmpty() || !xrefs.isEmpty()) {
QStringList refs;
foreach (const TranslatorMessage::Reference &ref, msg.allReferences())
refs.append(QString(QLatin1String("%2:%1"))
.arg(ref.lineNumber()).arg(ref.fileName()));
+ if (!xrefs.isEmpty())
+ refs << xrefs;
out << poWrappedEscapedLines(QLatin1String("#:"), true, refs.join(QLatin1String(" ")));
}