summaryrefslogtreecommitdiffstats
path: root/tools/linguist
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 /tools/linguist
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
Diffstat (limited to 'tools/linguist')
-rw-r--r--tools/linguist/shared/po.cpp24
1 files changed, 20 insertions, 4 deletions
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(" ")));
}