47 #include <QtCore/QString> |
47 #include <QtCore/QString> |
48 #include <QtCore/QTextCodec> |
48 #include <QtCore/QTextCodec> |
49 #include <QtCore/QTextStream> |
49 #include <QtCore/QTextStream> |
50 |
50 |
51 #include <ctype.h> |
51 #include <ctype.h> |
52 |
|
53 #define MAGIC_OBSOLETE_REFERENCE "Obsolete_PO_entries" |
|
54 |
52 |
55 // Uncomment if you wish to hard wrap long lines in .po files. Note that this |
53 // Uncomment if you wish to hard wrap long lines in .po files. Note that this |
56 // affects only msg strings, not comments. |
54 // affects only msg strings, not comments. |
57 //#define HARD_WRAP_LONG_WORDS |
55 //#define HARD_WRAP_LONG_WORDS |
58 |
56 |
553 } |
551 } |
554 // build translator message |
552 // build translator message |
555 TranslatorMessage msg; |
553 TranslatorMessage msg; |
556 msg.setContext(codec->toUnicode(item.context)); |
554 msg.setContext(codec->toUnicode(item.context)); |
557 if (!item.references.isEmpty()) { |
555 if (!item.references.isEmpty()) { |
|
556 QString xrefs; |
558 foreach (const QString &ref, |
557 foreach (const QString &ref, |
559 codec->toUnicode(item.references).split( |
558 codec->toUnicode(item.references).split( |
560 QRegExp(QLatin1String("\\s")), QString::SkipEmptyParts)) { |
559 QRegExp(QLatin1String("\\s")), QString::SkipEmptyParts)) { |
561 int pos = ref.lastIndexOf(QLatin1Char(':')); |
560 int pos = ref.indexOf(QLatin1Char(':')); |
562 if (pos != -1) |
561 int lpos = ref.lastIndexOf(QLatin1Char(':')); |
563 msg.addReference(ref.left(pos), ref.mid(pos + 1).toInt()); |
562 if (pos != -1 && pos == lpos) { |
|
563 bool ok; |
|
564 int lno = ref.mid(pos + 1).toInt(&ok); |
|
565 if (ok) { |
|
566 msg.addReference(ref.left(pos), lno); |
|
567 continue; |
|
568 } |
|
569 } |
|
570 if (!xrefs.isEmpty()) |
|
571 xrefs += QLatin1Char(' '); |
|
572 xrefs += ref; |
564 } |
573 } |
565 } else if (isObsolete) { |
574 if (!xrefs.isEmpty()) |
566 msg.setFileName(QLatin1String(MAGIC_OBSOLETE_REFERENCE)); |
575 item.extra[QLatin1String("po-references")] = xrefs; |
567 } |
576 } |
568 msg.setId(codec->toUnicode(item.id)); |
577 msg.setId(codec->toUnicode(item.id)); |
569 msg.setSourceText(codec->toUnicode(item.msgId)); |
578 msg.setSourceText(codec->toUnicode(item.msgId)); |
570 msg.setOldSourceText(codec->toUnicode(item.oldMsgId)); |
579 msg.setOldSourceText(codec->toUnicode(item.oldMsgId)); |
571 msg.setComment(codec->toUnicode(item.tscomment)); |
580 msg.setComment(codec->toUnicode(item.tscomment)); |
658 item.extra[QLatin1String("po-msgid_plural")] = |
667 item.extra[QLatin1String("po-msgid_plural")] = |
659 codec->toUnicode(extra); |
668 codec->toUnicode(extra); |
660 item.isPlural = true; |
669 item.isPlural = true; |
661 } else if (line.startsWith("#~ msgctxt ")) { |
670 } else if (line.startsWith("#~ msgctxt ")) { |
662 item.tscomment = slurpEscapedString(lines, l, 11, "#~ ", cd); |
671 item.tscomment = slurpEscapedString(lines, l, 11, "#~ ", cd); |
|
672 if (qtContexts) |
|
673 splitContext(&item.tscomment, &item.context); |
663 } else { |
674 } else { |
664 cd.appendError(QString(QLatin1String("PO-format parse error in line %1: '%2'")) |
675 cd.appendError(QString(QLatin1String("PO-format parse error in line %1: '%2'")) |
665 .arg(l + 1).arg(codec->toUnicode(lines[l]))); |
676 .arg(l + 1).arg(codec->toUnicode(lines[l]))); |
666 error = true; |
677 error = true; |
667 } |
678 } |
771 out << poEscapedLines(QLatin1String("#."), true, msg.extraComment()); |
782 out << poEscapedLines(QLatin1String("#."), true, msg.extraComment()); |
772 |
783 |
773 if (!msg.id().isEmpty()) |
784 if (!msg.id().isEmpty()) |
774 out << QLatin1String("#. ts-id ") << msg.id() << '\n'; |
785 out << QLatin1String("#. ts-id ") << msg.id() << '\n'; |
775 |
786 |
776 if (!msg.fileName().isEmpty() && msg.fileName() != QLatin1String(MAGIC_OBSOLETE_REFERENCE)) { |
787 QString xrefs = msg.extra(QLatin1String("po-references")); |
|
788 if (!msg.fileName().isEmpty() || !xrefs.isEmpty()) { |
777 QStringList refs; |
789 QStringList refs; |
778 foreach (const TranslatorMessage::Reference &ref, msg.allReferences()) |
790 foreach (const TranslatorMessage::Reference &ref, msg.allReferences()) |
779 refs.append(QString(QLatin1String("%2:%1")) |
791 refs.append(QString(QLatin1String("%2:%1")) |
780 .arg(ref.lineNumber()).arg(ref.fileName())); |
792 .arg(ref.lineNumber()).arg(ref.fileName())); |
|
793 if (!xrefs.isEmpty()) |
|
794 refs << xrefs; |
781 out << poWrappedEscapedLines(QLatin1String("#:"), true, refs.join(QLatin1String(" "))); |
795 out << poWrappedEscapedLines(QLatin1String("#:"), true, refs.join(QLatin1String(" "))); |
782 } |
796 } |
783 |
797 |
784 bool noWrap = false; |
798 bool noWrap = false; |
785 bool skipFormat = false; |
799 bool skipFormat = false; |