summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2009-07-20 11:51:58 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2009-07-20 11:51:58 (GMT)
commit1a632e1bc677fce4b8d5450ce4a971fdde3ed42f (patch)
tree222c48a9d90097b3ea61cb2839b6541eff185c3a /tools
parent9bd8df2b405ef517d2d1b209b8004aaaa4994242 (diff)
parent3d6381b47a6048d04dbfc7b6984cae81c02d4fe6 (diff)
downloadQt-1a632e1bc677fce4b8d5450ce4a971fdde3ed42f.zip
Qt-1a632e1bc677fce4b8d5450ce4a971fdde3ed42f.tar.gz
Qt-1a632e1bc677fce4b8d5450ce4a971fdde3ed42f.tar.bz2
Merge commit 'origin/4.5'
Conflicts: src/3rdparty/webkit/VERSION src/3rdparty/webkit/WebCore/ChangeLog src/3rdparty/webkit/WebCore/generated/JSDOMWindow.cpp src/3rdparty/webkit/WebCore/page/DOMWindow.idl src/corelib/io/qdiriterator.cpp src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp src/plugins/gfxdrivers/directfb/qdirectfbpixmap.h tests/auto/qxmlquery/tst_qxmlquery.cpp tools/linguist/lconvert/main.cpp
Diffstat (limited to 'tools')
-rw-r--r--tools/designer/src/lib/shared/widgetfactory.cpp6
-rw-r--r--tools/linguist/lconvert/main.cpp17
-rw-r--r--tools/linguist/linguist/messagemodel.cpp2
-rw-r--r--tools/linguist/lrelease/main.cpp1
-rw-r--r--tools/linguist/lupdate/main.cpp5
-rw-r--r--tools/linguist/shared/po.cpp5
-rw-r--r--tools/linguist/shared/qm.cpp3
-rw-r--r--tools/linguist/shared/translator.cpp42
-rw-r--r--tools/linguist/shared/translator.h7
-rw-r--r--tools/linguist/shared/ts.cpp4
-rw-r--r--tools/linguist/shared/xliff.cpp14
-rw-r--r--tools/xmlpatterns/qcoloringmessagehandler.cpp12
12 files changed, 78 insertions, 40 deletions
diff --git a/tools/designer/src/lib/shared/widgetfactory.cpp b/tools/designer/src/lib/shared/widgetfactory.cpp
index 6c45daf..7080ed3 100644
--- a/tools/designer/src/lib/shared/widgetfactory.cpp
+++ b/tools/designer/src/lib/shared/widgetfactory.cpp
@@ -834,9 +834,11 @@ bool WidgetFactory::isPassiveInteractor(QWidget *widget)
if (isTabBarInteractor(tabBar))
m_lastWasAPassiveInteractor = true;
return m_lastWasAPassiveInteractor;
- } else if (qobject_cast<QSizeGrip*>(widget))
+#ifndef QT_NO_SIZEGRIP
+ } else if (qobject_cast<QSizeGrip*>(widget)) {
return (m_lastWasAPassiveInteractor = true);
- else if (qobject_cast<QMdiSubWindow*>(widget))
+#endif
+ } else if (qobject_cast<QMdiSubWindow*>(widget))
return (m_lastWasAPassiveInteractor = true);
else if (qobject_cast<QAbstractButton*>(widget) && (qobject_cast<QTabBar*>(widget->parent()) || qobject_cast<QToolBox*>(widget->parent())))
return (m_lastWasAPassiveInteractor = true);
diff --git a/tools/linguist/lconvert/main.cpp b/tools/linguist/lconvert/main.cpp
index 4bed02f..1381595 100644
--- a/tools/linguist/lconvert/main.cpp
+++ b/tools/linguist/lconvert/main.cpp
@@ -81,8 +81,11 @@ static int usage(const QStringList &args)
" --output-format <outformat>\n"
" Specify output format. See -if.\n\n"
" --input-codec <codec>\n"
- " Specify encoding for QM input files. Default is 'Latin1'.\n"
- " UTF-8 is always tried as well, corresponding to the trUtf8() function.\n\n"
+ " Specify encoding for QM and PO input files. Default is 'Latin1'\n"
+ " for QM and 'UTF-8' for PO files. UTF-8 is always tried as well for\n"
+ " QM, corresponding to the possible use of the trUtf8() function.\n\n"
+ " --output-codec <codec>\n"
+ " Specify encoding for PO output files. Default is 'UTF-8'.\n\n"
" --drop-tags <regexp>\n"
" Drop named extra tags when writing TS or XLIFF files.\n"
" May be specified repeatedly.\n\n"
@@ -141,7 +144,6 @@ int main(int argc, char *argv[])
Translator::LocationsType locations = Translator::DefaultLocations;
ConversionData cd;
- cd.m_codecForSource = "Latin1";
Translator tr;
for (int i = 1; i < args.size(); ++i) {
@@ -174,6 +176,10 @@ int main(int argc, char *argv[])
if (++i >= args.size())
return usage(args);
cd.m_codecForSource = args[i].toLatin1();
+ } else if (args[i] == QLatin1String("-output-codec")) {
+ if (++i >= args.size())
+ return usage(args);
+ cd.m_outputCodec = args[i].toLatin1();
} else if (args[i] == QLatin1String("-drop-tag")) {
if (++i >= args.size())
return usage(args);
@@ -257,6 +263,11 @@ int main(int argc, char *argv[])
if (locations != Translator::DefaultLocations)
tr.setLocationsType(locations);
+ tr.normalizeTranslations(cd);
+ if (!cd.errors().isEmpty()) {
+ qWarning("%s", qPrintable(cd.error()));
+ cd.clearErrors();
+ }
if (!tr.save(outFileName, cd, outFormat)) {
qWarning("%s", qPrintable(cd.error()));
return 3;
diff --git a/tools/linguist/linguist/messagemodel.cpp b/tools/linguist/linguist/messagemodel.cpp
index 6bbf6f3..9995220 100644
--- a/tools/linguist/linguist/messagemodel.cpp
+++ b/tools/linguist/linguist/messagemodel.cpp
@@ -139,7 +139,7 @@ DataModel::DataModel(QObject *parent)
QStringList DataModel::normalizedTranslations(const MessageItem &m) const
{
- return Translator::normalizedTranslations(m.message(), m_language, m_country);
+ return Translator::normalizedTranslations(m.message(), m_numerusForms.count());
}
ContextItem *DataModel::contextItem(int context) const
diff --git a/tools/linguist/lrelease/main.cpp b/tools/linguist/lrelease/main.cpp
index d3b9937..5cb9e1a 100644
--- a/tools/linguist/lrelease/main.cpp
+++ b/tools/linguist/lrelease/main.cpp
@@ -121,6 +121,7 @@ static bool releaseTranslator(Translator &tor, const QString &qmFileName,
}
ConversionData cd;
+ tor.normalizeTranslations(cd);
cd.m_verbose = verbose;
cd.m_ignoreUnfinished = ignoreUnfinished;
cd.m_idBased = idBased;
diff --git a/tools/linguist/lupdate/main.cpp b/tools/linguist/lupdate/main.cpp
index ba5f45e..6a1edc4 100644
--- a/tools/linguist/lupdate/main.cpp
+++ b/tools/linguist/lupdate/main.cpp
@@ -203,6 +203,11 @@ static void updateTsFiles(const Translator &fetchedTor, const QStringList &tsFil
out.stripObsoleteMessages();
out.stripEmptyContexts();
+ out.normalizeTranslations(cd);
+ if (!cd.errors().isEmpty()) {
+ printOut(cd.error());
+ cd.clearErrors();
+ }
if (!out.save(fileName, cd, QLatin1String("auto"))) {
printOut(cd.error());
*fail = true;
diff --git a/tools/linguist/shared/po.cpp b/tools/linguist/shared/po.cpp
index e22aa7d..796d012 100644
--- a/tools/linguist/shared/po.cpp
+++ b/tools/linguist/shared/po.cpp
@@ -359,6 +359,7 @@ bool loadPO(Translator &translator, QIODevice &dev, ConversionData &cd)
const QChar quote = QLatin1Char('"');
const QChar newline = QLatin1Char('\n');
QTextStream in(&dev);
+ in.setCodec(cd.m_codecForSource.isEmpty() ? "UTF-8" : cd.m_codecForSource);
bool error = false;
// format of a .po file entry:
@@ -554,7 +555,7 @@ bool savePO(const Translator &translator, QIODevice &dev, ConversionData &cd)
{
bool ok = true;
QTextStream out(&dev);
- //qDebug() << "OUT CODEC: " << out.codec()->name();
+ out.setCodec(cd.m_outputCodec.isEmpty() ? "UTF-8" : cd.m_outputCodec);
bool first = true;
if (translator.messages().isEmpty() || !translator.messages().first().sourceText().isEmpty()) {
@@ -636,7 +637,7 @@ bool savePO(const Translator &translator, QIODevice &dev, ConversionData &cd)
if (plural.isEmpty())
plural = msg.sourceText();
out << poEscapedString(prefix, QLatin1String("msgid_plural"), noWrap, plural);
- QStringList translations = translator.normalizedTranslations(msg, cd, &ok);
+ const QStringList &translations = msg.translations();
for (int i = 0; i != translations.size(); ++i) {
QString str = translations.at(i);
str.replace(QChar(Translator::BinaryVariantSeparator),
diff --git a/tools/linguist/shared/qm.cpp b/tools/linguist/shared/qm.cpp
index 9523fde..638e997 100644
--- a/tools/linguist/shared/qm.cpp
+++ b/tools/linguist/shared/qm.cpp
@@ -552,7 +552,8 @@ bool loadQM(Translator &translator, QIODevice &dev, ConversionData &cd)
size_t numItems = offsetLength / (2 * sizeof(quint32));
//qDebug() << "NUMITEMS: " << numItems;
- QTextCodec *codec = QTextCodec::codecForName(cd.m_codecForSource);
+ QTextCodec *codec = QTextCodec::codecForName(
+ cd.m_codecForSource.isEmpty() ? "Latin1" : cd.m_codecForSource);
QTextCodec *utf8Codec = 0;
if (codec->name() != "UTF-8")
utf8Codec = QTextCodec::codecForName("UTF-8");
diff --git a/tools/linguist/shared/translator.cpp b/tools/linguist/shared/translator.cpp
index 305681d..62f4d10 100644
--- a/tools/linguist/shared/translator.cpp
+++ b/tools/linguist/shared/translator.cpp
@@ -517,16 +517,10 @@ QList<TranslatorMessage> Translator::translatedMessages() const
return result;
}
-QStringList Translator::normalizedTranslations(const TranslatorMessage &msg,
- QLocale::Language language, QLocale::Country country)
+QStringList Translator::normalizedTranslations(const TranslatorMessage &msg, int numPlurals)
{
QStringList translations = msg.translations();
- int numTranslations = 1;
- if (msg.isPlural() && language != QLocale::C) {
- QStringList forms;
- if (getNumerusInfo(language, country, 0, &forms))
- numTranslations = forms.count(); // includes singular
- }
+ int numTranslations = msg.isPlural() ? numPlurals : 1;
// make sure that the stringlist always have the size of the
// language's current numerus, or 1 if its not plural
@@ -540,21 +534,39 @@ QStringList Translator::normalizedTranslations(const TranslatorMessage &msg,
return translations;
}
-QStringList Translator::normalizedTranslations(const TranslatorMessage &msg,
- ConversionData &cd, bool *ok) const
+void Translator::normalizeTranslations(ConversionData &cd)
{
+ bool truncated = false;
QLocale::Language l;
QLocale::Country c;
languageAndCountry(languageCode(), &l, &c);
- QStringList translns = normalizedTranslations(msg, l, c);
- if (msg.translations().size() > translns.size() && ok) {
+ int numPlurals = 1;
+ if (l != QLocale::C) {
+ QStringList forms;
+ if (getNumerusInfo(l, c, 0, &forms))
+ numPlurals = forms.count(); // includes singular
+ }
+ for (int i = 0; i < m_messages.count(); ++i) {
+ const TranslatorMessage &msg = m_messages.at(i);
+ QStringList tlns = msg.translations();
+ int ccnt = msg.isPlural() ? numPlurals : 1;
+ if (tlns.count() != ccnt) {
+ while (tlns.count() < ccnt)
+ tlns.append(QString());
+ while (tlns.count() > ccnt) {
+ tlns.removeLast();
+ truncated = true;
+ }
+ TranslatorMessage msg2(msg);
+ msg2.setTranslations(tlns);
+ m_messages[i] = msg2;
+ }
+ }
+ if (truncated)
cd.appendError(QLatin1String(
"Removed plural forms as the target language has less "
"forms.\nIf this sounds wrong, possibly the target language is "
"not set or recognized.\n"));
- *ok = false;
- }
- return translns;
}
QString Translator::guessLanguageCodeFromFileName(const QString &filename)
diff --git a/tools/linguist/shared/translator.h b/tools/linguist/shared/translator.h
index fb17fd1..d0903a9 100644
--- a/tools/linguist/shared/translator.h
+++ b/tools/linguist/shared/translator.h
@@ -84,7 +84,8 @@ public:
public:
QString m_defaultContext;
- QByteArray m_codecForSource; // CPP specific
+ QByteArray m_codecForSource; // CPP, PO & QM specific
+ QByteArray m_outputCodec; // PO specific
QString m_sourceFileName;
QString m_targetFileName;
QDir m_sourceDir;
@@ -158,8 +159,8 @@ public:
static QString guessLanguageCodeFromFileName(const QString &fileName);
QList<TranslatorMessage> messages() const;
QList<TranslatorMessage> translatedMessages() const;
- static QStringList normalizedTranslations(const TranslatorMessage &m,
- QLocale::Language lang, QLocale::Country country);
+ static QStringList normalizedTranslations(const TranslatorMessage &m, int numPlurals);
+ void normalizeTranslations(ConversionData &cd);
QStringList normalizedTranslations(const TranslatorMessage &m, ConversionData &cd, bool *ok) const;
int messageCount() const { return m_messages.size(); }
diff --git a/tools/linguist/shared/ts.cpp b/tools/linguist/shared/ts.cpp
index 3efce15..5884997 100644
--- a/tools/linguist/shared/ts.cpp
+++ b/tools/linguist/shared/ts.cpp
@@ -693,8 +693,8 @@ bool saveTS(const Translator &translator, QIODevice &dev, ConversionData &cd, in
t << " type=\"obsolete\"";
if (msg.isPlural()) {
t << ">";
- QStringList translns = translator.normalizedTranslations(msg, cd, &result);
- for (int j = 0; j < qMax(1, translns.count()); ++j) {
+ const QStringList &translns = msg.translations();
+ for (int j = 0; j < translns.count(); ++j) {
t << "\n <numerusform";
writeVariants(t, " ", translns[j]);
t << "</numerusform>";
diff --git a/tools/linguist/shared/xliff.cpp b/tools/linguist/shared/xliff.cpp
index 1313172..c222b8d 100644
--- a/tools/linguist/shared/xliff.cpp
+++ b/tools/linguist/shared/xliff.cpp
@@ -243,13 +243,12 @@ static void writeComment(QTextStream &ts, const TranslatorMessage &msg, const QR
}
}
-static void writeTransUnits(QTextStream &ts, const TranslatorMessage &msg, const QRegExp &drops, int indent,
- const Translator &translator, ConversionData &cd, bool *ok)
+static void writeTransUnits(QTextStream &ts, const TranslatorMessage &msg, const QRegExp &drops, int indent)
{
static int msgid;
QString msgidstr = !msg.id().isEmpty() ? msg.id() : QString::fromAscii("_msg%1").arg(++msgid);
- QStringList translns = translator.normalizedTranslations(msg, cd, ok);
+ QStringList translns = msg.translations();
QHash<QString, QString>::const_iterator it;
QString pluralStr;
QStringList sources(msg.sourceText());
@@ -349,8 +348,7 @@ static void writeTransUnits(QTextStream &ts, const TranslatorMessage &msg, const
}
}
-static void writeMessage(QTextStream &ts, const TranslatorMessage &msg, const QRegExp &drops, int indent,
- const Translator &translator, ConversionData &cd, bool *ok)
+static void writeMessage(QTextStream &ts, const TranslatorMessage &msg, const QRegExp &drops, int indent)
{
if (msg.isPlural()) {
writeIndent(ts, indent);
@@ -364,12 +362,12 @@ static void writeMessage(QTextStream &ts, const TranslatorMessage &msg, const QR
writeLineNumber(ts, msg, indent);
writeComment(ts, msg, drops, indent);
- writeTransUnits(ts, msg, drops, indent, translator, cd, ok);
+ writeTransUnits(ts, msg, drops, indent);
--indent;
writeIndent(ts, indent);
ts << "</group>\n";
} else {
- writeTransUnits(ts, msg, drops, indent, translator, cd, ok);
+ writeTransUnits(ts, msg, drops, indent);
}
}
@@ -795,7 +793,7 @@ bool saveXLIFF(const Translator &translator, QIODevice &dev, ConversionData &cd)
}
foreach (const TranslatorMessage &msg, messageOrder[fn][ctx])
- writeMessage(ts, msg, drops, indent, translator, cd, &ok);
+ writeMessage(ts, msg, drops, indent);
if (!ctx.isEmpty()) {
--indent;
diff --git a/tools/xmlpatterns/qcoloringmessagehandler.cpp b/tools/xmlpatterns/qcoloringmessagehandler.cpp
index 9616097..0ddb246 100644
--- a/tools/xmlpatterns/qcoloringmessagehandler.cpp
+++ b/tools/xmlpatterns/qcoloringmessagehandler.cpp
@@ -100,12 +100,18 @@ void ColoringMessageHandler::handleMessage(QtMsgType type,
}
case QtFatalMsg:
{
- Q_ASSERT(!sourceLocation.isNull());
const QString errorCode(identifier.fragment());
Q_ASSERT(!errorCode.isEmpty());
QUrl uri(identifier);
uri.setFragment(QString());
+ QString location;
+
+ if(sourceLocation.isNull())
+ location = QXmlPatternistCLI::tr("Unknown location");
+ else
+ location = QString::fromLatin1(sourceLocation.uri().toEncoded());
+
QString errorId;
/* If it's a standard error code, we don't want to output the
* whole URI. */
@@ -117,7 +123,7 @@ void ColoringMessageHandler::handleMessage(QtMsgType type,
if(hasLine)
{
writeUncolored(QXmlPatternistCLI::tr("Error %1 in %2, at line %3, column %4: %5").arg(colorify(errorId, ErrorCode),
- colorify(QString::fromLatin1(sourceLocation.uri().toEncoded()), Location),
+ colorify(location, Location),
colorify(QString::number(sourceLocation.line()), Location),
colorify(QString::number(sourceLocation.column()), Location),
colorifyDescription(description)));
@@ -125,7 +131,7 @@ void ColoringMessageHandler::handleMessage(QtMsgType type,
else
{
writeUncolored(QXmlPatternistCLI::tr("Error %1 in %2: %3").arg(colorify(errorId, ErrorCode),
- colorify(QString::fromLatin1(sourceLocation.uri().toEncoded()), Location),
+ colorify(location, Location),
colorifyDescription(description)));
}
break;