tools/linguist/shared/translator.cpp
changeset 33 3e2da88830cd
parent 30 5dc02b23752f
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
    40 ****************************************************************************/
    40 ****************************************************************************/
    41 
    41 
    42 #include "translator.h"
    42 #include "translator.h"
    43 
    43 
    44 #include "simtexth.h"
    44 #include "simtexth.h"
       
    45 
       
    46 #include <iostream>
    45 
    47 
    46 #include <stdio.h>
    48 #include <stdio.h>
    47 #ifdef Q_OS_WIN
    49 #ifdef Q_OS_WIN
    48 // required for _setmode, to avoid _O_TEXT streams...
    50 // required for _setmode, to avoid _O_TEXT streams...
    49 # ifdef Q_OS_WINCE
    51 # ifdef Q_OS_WINCE
   584 
   586 
   585 void Translator::reportDuplicates(const Duplicates &dupes,
   587 void Translator::reportDuplicates(const Duplicates &dupes,
   586                                   const QString &fileName, bool verbose)
   588                                   const QString &fileName, bool verbose)
   587 {
   589 {
   588     if (!dupes.byId.isEmpty() || !dupes.byContents.isEmpty()) {
   590     if (!dupes.byId.isEmpty() || !dupes.byContents.isEmpty()) {
       
   591         std::cerr << "Warning: dropping duplicate messages in '" << qPrintable(fileName);
   589         if (!verbose) {
   592         if (!verbose) {
   590             qWarning("Warning: dropping duplicate messages in '%s'\n(try -verbose for more info).",
   593             std::cerr << "'\n(try -verbose for more info).\n";
   591                      qPrintable(fileName));
       
   592         } else {
   594         } else {
   593             qWarning("Warning: dropping duplicate messages in '%s':", qPrintable(fileName));
   595             std::cerr << "':\n";
   594             foreach (int i, dupes.byId)
   596             foreach (int i, dupes.byId)
   595                 qWarning("\n* ID: %s", qPrintable(message(i).id()));
   597                 std::cerr << "\n* ID: " << qPrintable(message(i).id()) << std::endl;
   596             foreach (int j, dupes.byContents) {
   598             foreach (int j, dupes.byContents) {
   597                 const TranslatorMessage &msg = message(j);
   599                 const TranslatorMessage &msg = message(j);
   598                 qWarning("\n* Context: %s\n* Source: %s",
   600                 std::cerr << "\n* Context: " << qPrintable(msg.context())
   599                         qPrintable(msg.context()),
   601                           << "\n* Source: " << qPrintable(msg.sourceText()) << std::endl;
   600                         qPrintable(msg.sourceText()));
       
   601                 if (!msg.comment().isEmpty())
   602                 if (!msg.comment().isEmpty())
   602                     qWarning("* Comment: %s", qPrintable(msg.comment()));
   603                     std::cerr << "* Comment: " << qPrintable(msg.comment()) << std::endl;
   603             }
   604             }
   604             qWarning();
   605             std::cerr << std::endl;
   605         }
   606         }
   606     }
   607     }
   607 }
   608 }
   608 
   609 
   609 // Used by lupdate to be able to search using absolute paths during merging
   610 // Used by lupdate to be able to search using absolute paths during merging
   686     }
   687     }
   687     if (truncated)
   688     if (truncated)
   688         cd.appendError(QLatin1String(
   689         cd.appendError(QLatin1String(
   689             "Removed plural forms as the target language has less "
   690             "Removed plural forms as the target language has less "
   690             "forms.\nIf this sounds wrong, possibly the target language is "
   691             "forms.\nIf this sounds wrong, possibly the target language is "
   691             "not set or recognized.\n"));
   692             "not set or recognized."));
   692 }
   693 }
   693 
   694 
   694 QString Translator::guessLanguageCodeFromFileName(const QString &filename)
   695 QString Translator::guessLanguageCodeFromFileName(const QString &filename)
   695 {
   696 {
   696     QString str = filename;
   697     QString str = filename;
   735 void Translator::setCodecName(const QByteArray &name)
   736 void Translator::setCodecName(const QByteArray &name)
   736 {
   737 {
   737     QTextCodec *codec = QTextCodec::codecForName(name);
   738     QTextCodec *codec = QTextCodec::codecForName(name);
   738     if (!codec) {
   739     if (!codec) {
   739         if (!name.isEmpty())
   740         if (!name.isEmpty())
   740             qWarning("No QTextCodec for %s available. Using Latin1\n", name.constData());
   741             std::cerr << "No QTextCodec for " << name.constData() << " available. Using Latin1.\n";
   741         m_codec = QTextCodec::codecForName("ISO-8859-1");
   742         m_codec = QTextCodec::codecForName("ISO-8859-1");
   742     } else {
   743     } else {
   743         m_codec = codec;
   744         m_codec = codec;
   744     }
   745     }
   745 }
   746 }