Changeset 561 for trunk/tools/linguist/shared/qm.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/tools/linguist/shared/qm.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the Qt Linguist of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 42 42 #include "translator.h" 43 43 44 #ifndef QT_BOOTSTRAPPED 44 45 #include <QtCore/QCoreApplication> 46 #endif 45 47 #include <QtCore/QDebug> 46 48 #include <QtCore/QDir> … … 173 175 bool save(QIODevice *iod); 174 176 175 void insert(const TranslatorMessage &msg, bool forceComment); 177 void insert(const TranslatorMessage &msg, const QStringList &tlns, bool forceComment); 178 void insertIdBased(const TranslatorMessage &message, const QStringList &tlns); 176 179 177 180 void squeeze(TranslatorSaveMode mode); … … 186 189 QByteArray originalBytes(const QString &str, bool isUtf8) const; 187 190 188 void insertInternal(const TranslatorMessage &message, bool forceComment, bool isUtf8); 191 void insertInternal(const TranslatorMessage &message, const QStringList &tlns, 192 bool forceComment, bool isUtf8); 189 193 190 194 static Prefix commonPrefix(const ByteTranslatorMessage &m1, const ByteTranslatorMessage &m2); … … 239 243 TranslatorSaveMode mode, Prefix prefix) const 240 244 { 241 for (int i = 0; i < msg.translations().count(); ++i) { 242 QString str = msg.translations().at(i); 243 str.replace(QChar(Translator::DefaultVariantSeparator), 244 QChar(Translator::InternalVariantSeparator)); 245 stream << quint8(Tag_Translation) << str; 246 } 245 for (int i = 0; i < msg.translations().count(); ++i) 246 stream << quint8(Tag_Translation) << msg.translations().at(i); 247 247 248 248 if (mode == SaveEverything) 249 249 prefix = HashContextSourceTextComment; 250 250 251 // lrelease produces "wrong" .qmfiles for QByteArrays that are .isNull().251 // lrelease produces "wrong" QM files for QByteArrays that are .isNull(). 252 252 switch (prefix) { 253 253 default: … … 417 417 } 418 418 419 void Releaser::insertInternal(const TranslatorMessage &message, bool forceComment, bool isUtf8) 419 void Releaser::insertInternal(const TranslatorMessage &message, const QStringList &tlns, 420 bool forceComment, bool isUtf8) 420 421 { 421 422 ByteTranslatorMessage bmsg(originalBytes(message.context(), isUtf8), 422 423 originalBytes(message.sourceText(), isUtf8), 423 424 originalBytes(message.comment(), isUtf8), 424 message.translations());425 tlns); 425 426 if (!forceComment) { 426 427 ByteTranslatorMessage bmsg2( … … 434 435 } 435 436 436 void Releaser::insert(const TranslatorMessage &message, bool forceComment)437 { 438 insertInternal(message, forceComment, message.isUtf8());437 void Releaser::insert(const TranslatorMessage &message, const QStringList &tlns, bool forceComment) 438 { 439 insertInternal(message, tlns, forceComment, message.isUtf8()); 439 440 if (message.isUtf8() && message.isNonUtf8()) 440 insertInternal(message, forceComment, false); 441 insertInternal(message, tlns, forceComment, false); 442 } 443 444 void Releaser::insertIdBased(const TranslatorMessage &message, const QStringList &tlns) 445 { 446 ByteTranslatorMessage bmsg("", originalBytes(message.id(), false), "", tlns); 447 m_messages.insert(bmsg, 0); 441 448 } 442 449 … … 546 553 //qDebug() << "NUMITEMS: " << numItems; 547 554 548 // FIXME: that's just a guess, the original locale data is lost...549 QTextCodec *codec = QTextCodec::codecForLocale();555 QTextCodec *codec = QTextCodec::codecForName( 556 cd.m_codecForSource.isEmpty() ? QByteArray("Latin1") : cd.m_codecForSource); 550 557 QTextCodec *utf8Codec = 0; 551 558 if (codec->name() != "UTF-8") 552 559 utf8Codec = QTextCodec::codecForName("UTF-8"); 560 561 QString strProN = QLatin1String("%n"); 562 QLocale::Language l; 563 QLocale::Country c; 564 Translator::languageAndCountry(translator.languageCode(), &l, &c); 565 QStringList numerusForms; 566 bool guessPlurals = true; 567 if (getNumerusInfo(l, c, 0, &numerusForms)) 568 guessPlurals = (numerusForms.count() == 1); 553 569 554 570 QString context, contextUtf8; … … 585 601 ((str.at(i).unicode() << 8) & 0xff00)); 586 602 } 587 str.replace(QChar(Translator::InternalVariantSeparator),588 QChar(Translator::DefaultVariantSeparator));589 603 translations << str; 590 604 m += len; … … 636 650 TranslatorMessage msg; 637 651 msg.setType(TranslatorMessage::Finished); 652 if (translations.count() > 1) { 653 // If guessPlurals is not false here, plural form discard messages 654 // will be spewn out later. 655 msg.setPlural(true); 656 } else if (guessPlurals) { 657 // This might cause false positives, so it is a fallback only. 658 if (sourcetext.contains(strProN)) 659 msg.setPlural(true); 660 } 638 661 msg.setTranslations(translations); 639 662 translations.clear(); … … 650 673 if (!(contextIsSystem && sourcetextIsSystem && commentIsSystem)) { 651 674 cd.appendError(QLatin1String( 652 "Cannot read file with current system charactercodec"));675 "Cannot read file with specified input codec")); 653 676 return false; 654 677 } … … 664 687 665 688 689 690 static bool containsStripped(const Translator &translator, const TranslatorMessage &msg) 691 { 692 foreach (const TranslatorMessage &tmsg, translator.messages()) 693 if (tmsg.sourceText() == msg.sourceText() 694 && tmsg.context() == msg.context() 695 && tmsg.comment().isEmpty()) 696 return true; 697 return false; 698 } 666 699 667 700 static bool saveQM(const Translator &translator, QIODevice &dev, ConversionData &cd) … … 679 712 int unfinished = 0; 680 713 int untranslated = 0; 714 int missingIds = 0; 715 int droppedData = 0; 681 716 682 717 for (int i = 0; i != translator.messageCount(); ++i) { … … 684 719 TranslatorMessage::Type typ = msg.type(); 685 720 if (typ != TranslatorMessage::Obsolete) { 721 if (cd.m_idBased && msg.id().isEmpty()) { 722 ++missingIds; 723 continue; 724 } 686 725 if (typ == TranslatorMessage::Unfinished) { 687 if ( msg.translation().isEmpty()) {726 if (!cd.m_idBased && msg.translation().isEmpty()) { 688 727 ++untranslated; 689 728 continue; … … 696 735 ++finished; 697 736 } 698 // Drop the comment in (context, sourceText, comment), 699 // unless the context is empty, 700 // unless (context, sourceText, "") already exists or 701 // unless we already dropped the comment of (context, 702 // sourceText, comment0). 703 bool forceComment = 704 msg.comment().isEmpty() 705 || msg.context().isEmpty() 706 || translator.contains(msg.context(), msg.sourceText(), QString()); 707 releaser.insert(msg, forceComment); 708 } 709 } 737 QStringList tlns = msg.translations(); 738 if (msg.type() == TranslatorMessage::Unfinished 739 && (cd.m_idBased || !cd.m_unTrPrefix.isEmpty())) 740 for (int j = 0; j < tlns.size(); ++j) 741 if (tlns.at(j).isEmpty()) 742 tlns[j] = cd.m_unTrPrefix + msg.sourceText(); 743 if (cd.m_idBased) { 744 if (!msg.context().isEmpty() || !msg.comment().isEmpty()) 745 ++droppedData; 746 releaser.insertIdBased(msg, tlns); 747 } else { 748 // Drop the comment in (context, sourceText, comment), 749 // unless the context is empty, 750 // unless (context, sourceText, "") already exists or 751 // unless we already dropped the comment of (context, 752 // sourceText, comment0). 753 bool forceComment = 754 msg.comment().isEmpty() 755 || msg.context().isEmpty() 756 || containsStripped(translator, msg); 757 releaser.insert(msg, tlns, forceComment); 758 } 759 } 760 } 761 762 if (missingIds) 763 cd.appendError(QCoreApplication::translate("LRelease", 764 "Dropped %n message(s) which had no ID.", 0, 765 QCoreApplication::CodecForTr, missingIds)); 766 if (droppedData) 767 cd.appendError(QCoreApplication::translate("LRelease", 768 "Excess context/disambiguation dropped from %n message(s).", 0, 769 QCoreApplication::CodecForTr, droppedData)); 710 770 711 771 releaser.squeeze(cd.m_saveMode);
Note:
See TracChangeset
for help on using the changeset viewer.