50 |
50 |
51 #include <QtXml/QXmlAttributes> |
51 #include <QtXml/QXmlAttributes> |
52 #include <QtXml/QXmlDefaultHandler> |
52 #include <QtXml/QXmlDefaultHandler> |
53 #include <QtXml/QXmlParseException> |
53 #include <QtXml/QXmlParseException> |
54 |
54 |
|
55 |
|
56 // The string value is historical and reflects the main purpose: Keeping |
|
57 // obsolete entries separate from the magic file message (which both have |
|
58 // no location information, but typically reside at opposite ends of the file). |
|
59 #define MAGIC_OBSOLETE_REFERENCE "Obsolete_PO_entries" |
55 |
60 |
56 QT_BEGIN_NAMESPACE |
61 QT_BEGIN_NAMESPACE |
57 |
62 |
58 /** |
63 /** |
59 * Implementation of XLIFF file format for Linguist |
64 * Implementation of XLIFF file format for Linguist |
690 { |
695 { |
691 if (m_sources.isEmpty()) { |
696 if (m_sources.isEmpty()) { |
692 m_cd.appendError(QLatin1String("XLIFF syntax error: Message without source string.")); |
697 m_cd.appendError(QLatin1String("XLIFF syntax error: Message without source string.")); |
693 return false; |
698 return false; |
694 } |
699 } |
|
700 if (m_type == TranslatorMessage::Obsolete && m_refs.size() == 1 |
|
701 && m_refs.at(0).fileName() == QLatin1String(MAGIC_OBSOLETE_REFERENCE)) |
|
702 m_refs.clear(); |
695 TranslatorMessage msg(m_context, m_sources[0], |
703 TranslatorMessage msg(m_context, m_sources[0], |
696 m_comment, QString(), QString(), -1, |
704 m_comment, QString(), QString(), -1, |
697 m_translations, m_type, isPlural); |
705 m_translations, m_type, isPlural); |
698 msg.setId(m_id); |
706 msg.setId(m_id); |
699 msg.setReferences(m_refs); |
707 msg.setReferences(m_refs); |
759 |
767 |
760 QHash<QString, QHash<QString, QList<TranslatorMessage> > > messageOrder; |
768 QHash<QString, QHash<QString, QList<TranslatorMessage> > > messageOrder; |
761 QHash<QString, QList<QString> > contextOrder; |
769 QHash<QString, QList<QString> > contextOrder; |
762 QList<QString> fileOrder; |
770 QList<QString> fileOrder; |
763 foreach (const TranslatorMessage &msg, translator.messages()) { |
771 foreach (const TranslatorMessage &msg, translator.messages()) { |
764 QHash<QString, QList<TranslatorMessage> > &file = messageOrder[msg.fileName()]; |
772 QString fn = msg.fileName(); |
|
773 if (fn.isEmpty() && msg.type() == TranslatorMessage::Obsolete) |
|
774 fn = QLatin1String(MAGIC_OBSOLETE_REFERENCE); |
|
775 QHash<QString, QList<TranslatorMessage> > &file = messageOrder[fn]; |
765 if (file.isEmpty()) |
776 if (file.isEmpty()) |
766 fileOrder.append(msg.fileName()); |
777 fileOrder.append(fn); |
767 QList<TranslatorMessage> &context = file[msg.context()]; |
778 QList<TranslatorMessage> &context = file[msg.context()]; |
768 if (context.isEmpty()) |
779 if (context.isEmpty()) |
769 contextOrder[msg.fileName()].append(msg.context()); |
780 contextOrder[fn].append(msg.context()); |
770 context.append(msg); |
781 context.append(msg); |
771 } |
782 } |
772 |
783 |
773 ts.setFieldAlignment(QTextStream::AlignRight); |
784 ts.setFieldAlignment(QTextStream::AlignRight); |
774 ts << "<?xml version=\"1.0\""; |
785 ts << "<?xml version=\"1.0\""; |