Commit cb1f2663 authored by Oswald Buddenhagen's avatar Oswald Buddenhagen Committed by The Qt Project
Browse files

purge TS 1.1 support


at the time of release it will be almost five years since we introduced
TS 2.0 and stopped writing 1.1 by default, so there shouldn't be much of
a need to write such files any more - and this commit doesn't even
remove 1.1 reading capability (because it comes for free so far).

Change-Id: Ie54fe31f83733ef944306c01301c0ec0e9bcb8bf
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 3028d134
dev 5.10 5.11 5.12 5.12.1 5.12.10 5.12.11 5.12.12 5.12.2 5.12.3 5.12.4 5.12.5 5.12.6 5.12.7 5.12.8 5.12.9 5.13 5.13.0 5.13.1 5.13.2 5.14 5.14.0 5.14.1 5.14.2 5.15 5.15.0 5.15.1 5.15.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 5.9.8 6.0 6.0.0 6.1 6.1.0 6.1.1 6.1.2 6.1.3 6.2 6.2.0 6.2.1 6.2.2 old/5.1 old/5.2 wip/cmake wip/winrt v5.15.0-alpha1 v5.14.1 v5.14.0 v5.14.0-rc2 v5.14.0-rc1 v5.14.0-beta3 v5.14.0-beta2 v5.14.0-beta1 v5.14.0-alpha1 v5.13.2 v5.13.1 v5.13.0 v5.13.0-rc3 v5.13.0-rc2 v5.13.0-rc1 v5.13.0-beta4 v5.13.0-beta3 v5.13.0-beta2 v5.13.0-beta1 v5.13.0-alpha1 v5.12.7 v5.12.6 v5.12.5 v5.12.4 v5.12.3 v5.12.2 v5.12.1 v5.12.0 v5.12.0-rc2 v5.12.0-rc1 v5.12.0-beta4 v5.12.0-beta3 v5.12.0-beta2 v5.12.0-beta1 v5.12.0-alpha1 v5.11.3 v5.11.2 v5.11.1 v5.11.0 v5.11.0-rc2 v5.11.0-rc1 v5.11.0-beta4 v5.11.0-beta3 v5.11.0-beta2 v5.11.0-beta1 v5.11.0-alpha1 v5.10.1 v5.10.0 v5.10.0-rc3 v5.10.0-rc2 v5.10.0-rc1 v5.10.0-beta4 v5.10.0-beta3 v5.10.0-beta2 v5.10.0-beta1 v5.10.0-alpha1 v5.9.9 v5.9.8 v5.9.7 v5.9.6 v5.9.5 v5.9.4 v5.9.3 v5.9.2 v5.9.1 v5.9.0 v5.9.0-rc2 v5.9.0-rc1 v5.9.0-beta4 v5.9.0-beta3 v5.9.0-beta2 v5.9.0-beta1 v5.9.0-alpha1 v5.8.0 v5.8.0-rc1 v5.8.0-beta1 v5.8.0-alpha1 v5.7.1 v5.7.0 v5.7.0-rc1 v5.7.0-beta1 v5.7.0-alpha1 v5.6.3 v5.6.2 v5.6.1 v5.6.1-1 v5.6.0 v5.6.0-rc1 v5.6.0-beta1 v5.6.0-alpha1 v5.5.1 v5.5.0 v5.5.0-rc1 v5.5.0-beta1 v5.5.0-alpha1 v5.4.2 v5.4.1 v5.4.0 v5.4.0-rc1 v5.4.0-beta1 v5.4.0-alpha1 v5.3.2 v5.3.1 v5.3.0 v5.3.0-rc1 v5.3.0-beta1 v5.3.0-alpha1 v5.2.1 v5.2.0 v5.2.0-rc1 v5.2.0-beta1 v5.2.0-alpha1 v5.1.1 v5.1.0 v5.1.0-rc2 v5.1.0-rc1 v5.1.0-beta1 v5.1.0-alpha1
No related merge requests found
Showing with 16 additions and 166 deletions
......@@ -60,10 +60,6 @@ QT_BEGIN_NAMESPACE
* in that encoding or as UTF-8 to trUtf8() if it is flagged as such.
* For ts 2.0, the file content is always uniformly in UTF-8. The file stores
* the codecForTr default and marks deviating messages accordingly.
* For ts 1.1, the file content is in mixed encoding. Each message is encoded
* the way it will be passed to tr() (with 8-bit characters encoded as numeric
* entities) or trUtf8(). The file stores the encoding and codecForTr in one
* attribute, for both the default and each deviating message.
*/
......@@ -504,33 +500,6 @@ static QString protect(const QString &str)
return result;
}
static QString evilBytes(const QString& str,
bool isUtf8, int format, const QByteArray &codecName)
{
//qDebug() << "EVIL: " << str << isUtf8 << format << codecName;
if (isUtf8)
return protect(str);
if (format == 20)
return protect(str);
if (codecName == "UTF-8")
return protect(str);
QTextCodec *codec = QTextCodec::codecForName(codecName);
if (!codec)
return protect(str);
QString t = QString::fromLatin1(codec->fromUnicode(protect(str)).data());
int len = (int) t.length();
QString result;
// FIXME: Factor is sensible only for latin scripts, probably.
result.reserve(t.length() * 2);
for (int k = 0; k < len; k++) {
if (t[k].unicode() >= 0x7f)
result += numericEntity(t[k].unicode());
else
result += t[k];
}
return result;
}
static void writeExtras(QTextStream &t, const char *indent,
const TranslatorMessage::ExtraData &extras, QRegExp drops)
{
......@@ -570,31 +539,25 @@ static void writeVariants(QTextStream &t, const char *indent, const QString &inp
}
}
bool saveTS(const Translator &translator, QIODevice &dev, ConversionData &cd, int format)
bool saveTS(const Translator &translator, QIODevice &dev, ConversionData &cd)
{
bool result = true;
QTextStream t(&dev);
t.setCodec(QTextCodec::codecForName("UTF-8"));
bool trIsUtf8 = (translator.codecName() == "UTF-8");
//qDebug() << translator.codecName();
bool fileIsUtf8 = (format == 20 || trIsUtf8);
// The xml prolog allows processors to easily detect the correct encoding
t << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE TS>\n";
if (format == 11)
t << "<TS version=\"1.1\"";
else
t << "<TS version=\"2.0\"";
t << "<TS version=\"2.0\"";
QString languageCode = translator.languageCode();
if (!languageCode.isEmpty() && languageCode != QLatin1String("C"))
t << " language=\"" << languageCode << "\"";
if (format == 20) {
languageCode = translator.sourceLanguageCode();
if (!languageCode.isEmpty() && languageCode != QLatin1String("C"))
t << " sourcelanguage=\"" << languageCode << "\"";
}
languageCode = translator.sourceLanguageCode();
if (!languageCode.isEmpty() && languageCode != QLatin1String("C"))
t << " sourcelanguage=\"" << languageCode << "\"";
t << ">\n";
QByteArray codecName = translator.codecName();
......@@ -611,8 +574,7 @@ bool saveTS(const Translator &translator, QIODevice &dev, ConversionData &cd, in
QRegExp drops(cd.dropTags().join(QLatin1String("|")));
if (format == 20)
writeExtras(t, " ", translator.extras(), drops);
writeExtras(t, " ", translator.extras(), drops);
QHash<QString, QList<TranslatorMessage> > messageOrder;
QList<QString> contextOrder;
......@@ -632,34 +594,23 @@ bool saveTS(const Translator &translator, QIODevice &dev, ConversionData &cd, in
QHash<QString, int> currentLine;
QString currentFile;
foreach (const QString &context, contextOrder) {
const TranslatorMessage &firstMsg = messageOrder[context].first();
t << "<context" << ((!fileIsUtf8 && firstMsg.isUtf8()) ? " encoding=\"UTF-8\"" : "") << ">\n";
t << " <name>"
<< evilBytes(context, firstMsg.isUtf8() || fileIsUtf8, format, codecName)
t << "<context>\n"
" <name>"
<< protect(context)
<< "</name>\n";
foreach (const TranslatorMessage &msg, messageOrder[context]) {
//msg.dump();
bool isUtf8 = msg.isUtf8();
bool second = false;
forever {
t << " <message";
if (!msg.id().isEmpty())
t << " id=\"" << msg.id() << "\"";
if (!trIsUtf8) {
if (format == 11) {
if (isUtf8)
t << " encoding=\"UTF-8\"";
} else {
if (msg.isUtf8()) {
if (msg.isNonUtf8())
t << " utf8=\"both\"";
else
t << " utf8=\"true\"";
}
}
}
if (msg.isPlural())
t << " numerus=\"yes\"";
......@@ -703,20 +654,18 @@ bool saveTS(const Translator &translator, QIODevice &dev, ConversionData &cd, in
}
t << " <source>"
<< evilBytes(msg.sourceText(), isUtf8, format, codecName)
<< protect(msg.sourceText())
<< "</source>\n";
if (format != 11 && !msg.oldSourceText().isEmpty())
if (!msg.oldSourceText().isEmpty())
t << " <oldsource>" << protect(msg.oldSourceText()) << "</oldsource>\n";
if (!msg.comment().isEmpty()) {
t << " <comment>"
<< evilBytes(msg.comment(), isUtf8, format, codecName)
<< protect(msg.comment())
<< "</comment>\n";
}
if (format != 11) {
if (!msg.oldComment().isEmpty())
t << " <oldcomment>" << protect(msg.oldComment()) << "</oldcomment>\n";
......@@ -728,8 +677,6 @@ bool saveTS(const Translator &translator, QIODevice &dev, ConversionData &cd, in
t << " <translatorcomment>" << protect(msg.translatorComment())
<< "</translatorcomment>\n";
}
t << " <translation";
if (msg.type() == TranslatorMessage::Unfinished)
t << " type=\"unfinished\"";
......@@ -749,18 +696,11 @@ bool saveTS(const Translator &translator, QIODevice &dev, ConversionData &cd, in
}
t << "</translation>\n";
if (format != 11)
writeExtras(t, " ", msg.extras(), drops);
writeExtras(t, " ", msg.extras(), drops);
if (!msg.userData().isEmpty())
t << " <userdata>" << msg.userData() << "</userdata>\n";
t << " </message>\n";
if (format != 11 || second || !msg.isUtf8() || !msg.isNonUtf8())
break;
isUtf8 = false;
second = true;
}
}
t << "</context>\n";
}
......@@ -775,43 +715,16 @@ bool loadTS(Translator &translator, QIODevice &dev, ConversionData &cd)
return reader.read(translator);
}
bool saveTS11(const Translator &translator, QIODevice &dev, ConversionData &cd)
{
return saveTS(translator, dev, cd, 11);
}
bool saveTS20(const Translator &translator, QIODevice &dev, ConversionData &cd)
{
return saveTS(translator, dev, cd, 20);
}
int initTS()
{
Translator::FileFormat format;
format.extension = QLatin1String("ts11");
format.fileType = Translator::FileFormat::TranslationSource;
format.priority = -1;
format.description = QObject::tr("Qt translation sources (format 1.1)");
format.loader = &loadTS;
format.saver = &saveTS11;
Translator::registerFileFormat(format);
format.extension = QLatin1String("ts20");
format.fileType = Translator::FileFormat::TranslationSource;
format.priority = -1;
format.description = QObject::tr("Qt translation sources (format 2.0)");
format.loader = &loadTS;
format.saver = &saveTS20;
Translator::registerFileFormat(format);
// "ts" is always the latest. right now it's ts20.
format.extension = QLatin1String("ts");
format.fileType = Translator::FileFormat::TranslationSource;
format.priority = 0;
format.description = QObject::tr("Qt translation sources (latest format)");
format.description = QObject::tr("Qt translation sources");
format.loader = &loadTS;
format.saver = &saveTS20;
format.saver = &saveTS;
Translator::registerFileFormat(format);
return 1;
......
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="1.1" language="de_DE">
<context>
<name>FindDialog</name>
<message>
<location filename="finddialog.cpp" line="57"/>
<source>Enter the text you want to find.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="finddialog.cpp" line="107"/>
<source>Search reached end of the document</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="finddialog.cpp" line="109"/>
<source>Search reached start of the document</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="finddialog.cpp" line="111"/>
<source>Text not found</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="finddialog.cpp" line="122"/>
<source>Should be obsolete</source>
<translation type="unfinished">SHOULD BE OBSOLETE</translation>
</message>
</context>
</TS>
......@@ -285,9 +285,7 @@ void tst_lconvert::roundtrips_data()
QStringList poTsPo; poTsPo << "po" << "ts" << "po";
QStringList poXlfPo; poXlfPo << "po" << "xlf" << "po";
QStringList tsTs11Ts; tsTs11Ts << "ts" << "ts11" << "ts";
QStringList tsPoTs; tsPoTs << "ts" << "po" << "ts";
QStringList ts11PoTs11; ts11PoTs11 << "ts11" << "po" << "ts11";
QStringList tsXlfTs; tsXlfTs << "ts" << "xlf" << "ts";
QStringList tsQmTs; tsQmTs << "ts" << "qm" << "ts";
......@@ -301,7 +299,6 @@ void tst_lconvert::roundtrips_data()
QTest::newRow("po-ts-po (developer comment)") << "test-developer-comment.po" << poTsPo << noArgs;
QTest::newRow("po-xliff-po (developer comment)") << "test-developer-comment.po" << poXlfPo << noArgs;
QTest::newRow("ts11-po-ts11") << "test11.ts" << ts11PoTs11 << filterPoArgs;
QTest::newRow("ts20-po-ts20") << "test20.ts" << tsPoTs << filterPoArgs;
QTest::newRow("po-ts-po (de)") << "test1-de.po" << poTsPo << noArgs;
QTest::newRow("po-ts-po (cn)") << "test1-cn.po" << poTsPo << noArgs;
......@@ -319,10 +316,6 @@ void tst_lconvert::roundtrips_data()
QTest::newRow("po-ts-po (references)") << "test-refs.po" << poTsPo << noArgs;
QTest::newRow("ts20-ts11-ts20 (utf8)") << "codec-utf8.ts" << tsTs11Ts << noArgs;
QTest::newRow("ts20-ts11-ts20 (cp1252)") << "codec-cp1252.ts" << tsTs11Ts << noArgs;
QTest::newRow("ts20-ts11-ts20 (dual-encoding)") << "dual-encoding.ts" << tsTs11Ts << noArgs;
QTest::newRow("ts-qm-ts (dual-encoding)") << "dual-encoding.ts" << tsQmTs << noArgs;
QTest::newRow("ts-qm-ts (plurals-de)") << "plurals-de.ts" << tsQmTs << outDeArgs;
QTest::newRow("ts-qm-ts (plurals-cn)") << "plurals-cn.ts" << tsQmTs << outCnArgs;
......
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="1.1">
<defaultcodec>windows-1252</defaultcodec>
<context>
<name>FooBar</name>
<message>
<location filename="main.cpp" line="11"/>
<source>this contains an umlaut &#xfc; &amp;uuml;</source>
<translation>random stuff with umlaut</translation>
</message>
<message encoding="UTF-8">
<location filename="main.cpp" line="13"/>
<source>umlaut ü &amp;uuml; in utf8</source>
<translation>more random stuff with umlaut</translation>
</message>
</context>
</TS>
......@@ -173,16 +173,10 @@ void tst_lrelease::translate()
void tst_lrelease::mixedcodecs()
{
QVERIFY(!QProcess::execute(binDir + "/lrelease " + dataDir + "mixedcodecs-ts11.ts"));
QVERIFY(!QProcess::execute(binDir + "/lrelease " + dataDir + "mixedcodecs-ts20.ts"));
#ifdef Q_OS_WIN
QVERIFY(!QProcess::execute("fc /b testdata\\mixedcodecs-ts11.qm testdata\\mixedcodecs-ts20.qm"));
#else
QVERIFY(!QProcess::execute("cmp " + dataDir + "mixedcodecs-ts11.qm " + dataDir + "mixedcodecs-ts20.qm"));
#endif
QTranslator translator;
QVERIFY(translator.load(dataDir + "mixedcodecs-ts11.qm"));
QVERIFY(translator.load(dataDir + "mixedcodecs-ts20.qm"));
qApp->installTranslator(&translator);
QCOMPARE(QCoreApplication::translate("FooBar", "this contains an umlaut \xfc &uuml;"),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment