if (!CppFiles::isBlacklisted(filename))
if (const Translator *tor = CppFiles::getTranslator(filename))
foreach (const TranslatorMessage &msg, tor->messages())
- translator.extend(msg);
+ translator.extend(msg, cd);
}
QT_END_NAMESPACE
static void recordMessage(
Translator *tor, const QString &context, const QString &text, const QString &comment,
- const QString &extracomment, bool plural)
+ const QString &extracomment, bool plural, ConversionData &cd)
{
TranslatorMessage msg(
context, text, comment, QString(),
yyFileName, yyLineNo, QStringList(),
TranslatorMessage::Unfinished, plural);
msg.setExtraComment(extracomment.simplified());
- tor->extend(msg);
+ tor->extend(msg, cd);
}
-static void parse( Translator *tor )
+static void parse(Translator *tor, ConversionData &cd)
{
QString text;
QString com;
}
}
if (!text.isEmpty())
- recordMessage(tor, context(), text, com, extracomment, plural);
+ recordMessage(tor, context(), text, com, extracomment, plural, cd);
}
break;
case Tok_translate:
}
}
if (!text.isEmpty())
- recordMessage(tor, contextOverride, text, com, extracomment, plural);
+ recordMessage(tor, contextOverride, text, com, extracomment, plural, cd);
}
}
break;
yyCurLineNo = 1;
yyParenLineNo = 1;
- parse(&translator);
+ parse(&translator, cd);
return true;
}
class FindTrCalls: protected AST::Visitor
{
public:
- FindTrCalls(Engine *engine)
+ FindTrCalls(Engine *engine, ConversionData &cd)
: engine(engine)
+ , m_cd(cd)
{
}
msg.setExtraComment(extracomment.simplified());
msg.setId(msgid);
msg.setExtras(extra);
- m_translator->extend(msg);
+ m_translator->extend(msg, m_cd);
consumeComment();
} else if (name == QLatin1String("qsTranslate") ||
name == QLatin1String("QT_TRANSLATE_NOOP")) {
msg.setExtraComment(extracomment.simplified());
msg.setId(msgid);
msg.setExtras(extra);
- m_translator->extend(msg);
+ m_translator->extend(msg, m_cd);
consumeComment();
} else if (name == QLatin1String("qsTrId") ||
name == QLatin1String("QT_TRID_NOOP")) {
msg.setExtraComment(extracomment.simplified());
msg.setId(id);
msg.setExtras(extra);
- m_translator->extend(msg);
+ m_translator->extend(msg, m_cd);
consumeComment();
}
}
Engine *engine;
Translator *m_translator;
+ ConversionData &m_cd;
QString m_fileName;
QString m_component;
driver.setLexer(&lexer);
if (qmlMode ? parser.parse() : parser.parseProgram()) {
- FindTrCalls trCalls(&driver);
+ FindTrCalls trCalls(&driver, cd);
//find all tr calls in the code
trCalls(&translator, filename, parser.rootNode());
m_comment, QString(), m_cd.m_sourceFileName,
m_lineNumber, QStringList());
msg.setExtraComment(m_extracomment);
- m_translator.extend(msg);
+ m_translator.extend(msg, m_cd);
}
m_source.clear();
if (!m_insideStringList) {
}
}
-void Translator::extend(const TranslatorMessage &msg)
+static QString elidedId(const QString &id, int len)
+{
+ return id.length() <= len ? id : id.left(len - 5) + QLatin1String("[...]");
+}
+
+static QString makeMsgId(const TranslatorMessage &msg)
+{
+ QString id = msg.context() + QLatin1String("//") + elidedId(msg.sourceText(), 100);
+ if (!msg.comment().isEmpty())
+ id += QLatin1String("//") + elidedId(msg.comment(), 30);
+ return id;
+}
+
+void Translator::extend(const TranslatorMessage &msg, ConversionData &cd)
{
int index = find(msg);
if (index == -1) {
append(msg);
} else {
TranslatorMessage &emsg = m_messages[index];
+ if (emsg.sourceText().isEmpty()) {
+ emsg.setSourceText(msg.sourceText());
+ } else if (!msg.sourceText().isEmpty() && emsg.sourceText() != msg.sourceText()) {
+ cd.appendError(QString::fromLatin1("Contradicting source strings for message with id '%1'.")
+ .arg(emsg.id()));
+ return;
+ }
+ if (emsg.extras().isEmpty()) {
+ emsg.setExtras(msg.extras());
+ } else if (!msg.extras().isEmpty() && emsg.extras() != msg.extras()) {
+ cd.appendError(QString::fromLatin1("Contradicting meta data for for %1.")
+ .arg(!emsg.id().isEmpty()
+ ? QString::fromLatin1("message with id '%1'").arg(emsg.id())
+ : QString::fromLatin1("message '%1'").arg(makeMsgId(msg))));
+ return;
+ }
emsg.addReferenceUniq(msg.fileName(), msg.lineNumber());
if (!msg.extraComment().isEmpty()) {
QString cmt = emsg.extraComment();
int find(const QString &context) const;
void replaceSorted(const TranslatorMessage &msg);
- void extend(const TranslatorMessage &msg); // Only for single-location messages
+ void extend(const TranslatorMessage &msg, ConversionData &cd); // Only for single-location messages
void append(const TranslatorMessage &msg);
void appendSorted(const TranslatorMessage &msg);
+//: commented
+qtTrId("lollipop");
+//% "this is the source text"
+//~ meta so-meta
+//: even more commented
+qtTrId("lollipop");
+//% "this is contradicting source text"
+qtTrId("lollipop");
+//~ meta too-much-meta
+qtTrId("lollipop");
+
+
+//~ meta so-meta
+QObject::tr("another message", "here with a lot of noise in the comment so it is long enough");
+
+//~ meta too-much-meta
+QObject::tr("another message", "here with a lot of noise in the comment so it is long enough");
<!DOCTYPE TS>
<TS version="2.0">
<context>
+ <name></name>
+ <message id="lollipop">
+ <location filename="main.cpp" line="51"/>
+ <location filename="main.cpp" line="56"/>
+ <source>this is the source text</source>
+ <extracomment>commented
+----------
+even more commented</extracomment>
+ <translation type="unfinished"></translation>
+ <extra-meta>so-meta</extra-meta>
+ </message>
+</context>
+<context>
+ <name>QObject</name>
+ <message>
+ <location filename="main.cpp" line="67"/>
+ <source>another message</source>
+ <comment>here with a lot of noise in the comment so it is long enough</comment>
+ <translation type="unfinished"></translation>
+ <extra-meta>so-meta</extra-meta>
+ </message>
+</context>
+<context>
<name>context</name>
<message>
<location filename="finddialog.cpp" line="42"/>