Speed up starting translation tests.
--HG-- branch : develop
This commit is contained in:
parent
4916b8d2e4
commit
eeb7c86d74
|
@ -48,7 +48,9 @@ SOURCES += \
|
||||||
tst_qmuparsererrormsg.cpp \
|
tst_qmuparsererrormsg.cpp \
|
||||||
tst_tstranslation.cpp \
|
tst_tstranslation.cpp \
|
||||||
tst_buitinregexp.cpp \
|
tst_buitinregexp.cpp \
|
||||||
tst_abstractregexp.cpp
|
tst_abstractregexp.cpp \
|
||||||
|
tst_tslocaletranslation.cpp \
|
||||||
|
tst_abstracttranslation.cpp
|
||||||
|
|
||||||
*msvc*:SOURCES += stable.cpp
|
*msvc*:SOURCES += stable.cpp
|
||||||
|
|
||||||
|
@ -58,7 +60,9 @@ HEADERS += \
|
||||||
tst_qmuparsererrormsg.h \
|
tst_qmuparsererrormsg.h \
|
||||||
tst_tstranslation.h \
|
tst_tstranslation.h \
|
||||||
tst_buitinregexp.h \
|
tst_buitinregexp.h \
|
||||||
tst_abstractregexp.h
|
tst_abstractregexp.h \
|
||||||
|
tst_tslocaletranslation.h \
|
||||||
|
tst_abstracttranslation.h
|
||||||
|
|
||||||
# Set using ccache. Function enable_ccache() defined in common.pri.
|
# Set using ccache. Function enable_ccache() defined in common.pri.
|
||||||
$$enable_ccache()
|
$$enable_ccache()
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "tst_buitinregexp.h"
|
#include "tst_buitinregexp.h"
|
||||||
#include "tst_qmuparsererrormsg.h"
|
#include "tst_qmuparsererrormsg.h"
|
||||||
#include "tst_tstranslation.h"
|
#include "tst_tstranslation.h"
|
||||||
|
#include "tst_tslocaletranslation.h"
|
||||||
|
|
||||||
#include "../vmisc/def.h"
|
#include "../vmisc/def.h"
|
||||||
#include "../vmisc/testvapplication.h"
|
#include "../vmisc/testvapplication.h"
|
||||||
|
@ -50,21 +51,15 @@ int main(int argc, char** argv)
|
||||||
ASSERT_TEST(new TST_TSTranslation());
|
ASSERT_TEST(new TST_TSTranslation());
|
||||||
|
|
||||||
const QStringList locales = SupportedLocales();
|
const QStringList locales = SupportedLocales();
|
||||||
for(quint32 s = 0; s < TST_MeasurementRegExp::systemCounts; ++s)
|
for(int l = 0, sz = locales.size(); l < sz; ++l)
|
||||||
{
|
{
|
||||||
for(int l = 0, sz = locales.size(); l < sz; ++l)
|
for(quint32 s = 0; s < TST_MeasurementRegExp::systemCounts; ++s)
|
||||||
{
|
{
|
||||||
ASSERT_TEST(new TST_MeasurementRegExp(s, locales.at(l)));
|
ASSERT_TEST(new TST_MeasurementRegExp(s, locales.at(l)));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for(int l = 0, sz = locales.size(); l < sz; ++l)
|
ASSERT_TEST(new TST_TSLocaleTranslation(locales.at(l)));
|
||||||
{
|
|
||||||
ASSERT_TEST(new TST_BuitInRegExp(locales.at(l)));
|
ASSERT_TEST(new TST_BuitInRegExp(locales.at(l)));
|
||||||
}
|
|
||||||
|
|
||||||
for(int l = 0, sz = locales.size(); l < sz; ++l)
|
|
||||||
{
|
|
||||||
ASSERT_TEST(new TST_QmuParserErrorMsg(locales.at(l)));
|
ASSERT_TEST(new TST_QmuParserErrorMsg(locales.at(l)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
89
src/test/TranslationsTest/tst_abstracttranslation.cpp
Normal file
89
src/test/TranslationsTest/tst_abstracttranslation.cpp
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file tst_abstracttranslation.cpp
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 17 2, 2018
|
||||||
|
**
|
||||||
|
** @brief
|
||||||
|
** @copyright
|
||||||
|
** This source code is part of the Valentina project, a pattern making
|
||||||
|
** program, whose allow create and modeling patterns of clothing.
|
||||||
|
** Copyright (C) 2018 Valentina project
|
||||||
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
||||||
|
**
|
||||||
|
** Valentina is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 3 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** Valentina is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
**
|
||||||
|
*************************************************************************/
|
||||||
|
#include "tst_abstracttranslation.h"
|
||||||
|
|
||||||
|
#include <QtTest>
|
||||||
|
|
||||||
|
const QString TST_AbstractTranslation::TagName = QStringLiteral("name");
|
||||||
|
const QString TST_AbstractTranslation::TagMessage = QStringLiteral("message");
|
||||||
|
const QString TST_AbstractTranslation::TagSource = QStringLiteral("source");
|
||||||
|
const QString TST_AbstractTranslation::TagTranslation = QStringLiteral("translation");
|
||||||
|
|
||||||
|
const QString TST_AbstractTranslation::AttrType = QStringLiteral("type");
|
||||||
|
const QString TST_AbstractTranslation::AttrValVanished = QStringLiteral("vanished");
|
||||||
|
const QString TST_AbstractTranslation::AttrValUnfinished = QStringLiteral("unfinished");
|
||||||
|
const QString TST_AbstractTranslation::AttrValObsolete = QStringLiteral("obsolete");
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
TST_AbstractTranslation::TST_AbstractTranslation(QObject *parent)
|
||||||
|
: QObject(parent),
|
||||||
|
tsFile(),
|
||||||
|
tsXML()
|
||||||
|
{}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QDomNodeList TST_AbstractTranslation::LoadTSFile(const QString &filename)
|
||||||
|
{
|
||||||
|
tsFile.reset();
|
||||||
|
tsFile = QSharedPointer<QFile>(new QFile(QString("%1/%2").arg(TS_DIR).arg(filename)));
|
||||||
|
if (not tsFile->exists())
|
||||||
|
{
|
||||||
|
const QString message = QString("Can't find '%1'.\n%2.").arg(filename).arg(tsFile->errorString());
|
||||||
|
QWARN(qUtf8Printable(message));
|
||||||
|
return QDomNodeList();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tsFile->open(QIODevice::ReadOnly) == false)
|
||||||
|
{
|
||||||
|
const QString message = QString("Can't open file '%1'.\n%2.").arg(filename).arg(tsFile->errorString());
|
||||||
|
QWARN(qUtf8Printable(message));
|
||||||
|
return QDomNodeList();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString errorMsg;
|
||||||
|
int errorLine = -1;
|
||||||
|
int errorColumn = -1;
|
||||||
|
tsXML.reset();
|
||||||
|
tsXML = QSharedPointer<QDomDocument>(new QDomDocument());
|
||||||
|
if (tsXML->setContent(tsFile.data(), &errorMsg, &errorLine, &errorColumn) == false)
|
||||||
|
{
|
||||||
|
const QString message = QString("Parsing error file %1 in line %2 column %3.")
|
||||||
|
.arg(filename).arg(errorLine).arg(errorColumn);
|
||||||
|
QWARN(qUtf8Printable(message));
|
||||||
|
return QDomNodeList();
|
||||||
|
}
|
||||||
|
|
||||||
|
const QDomNodeList messages = tsXML->elementsByTagName(TagMessage);
|
||||||
|
if (messages.isEmpty())
|
||||||
|
{
|
||||||
|
QWARN("File doesn't contain any messages.");
|
||||||
|
return QDomNodeList();
|
||||||
|
}
|
||||||
|
|
||||||
|
return messages;
|
||||||
|
}
|
62
src/test/TranslationsTest/tst_abstracttranslation.h
Normal file
62
src/test/TranslationsTest/tst_abstracttranslation.h
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file tst_abstracttranslation.h
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 17 2, 2018
|
||||||
|
**
|
||||||
|
** @brief
|
||||||
|
** @copyright
|
||||||
|
** This source code is part of the Valentina project, a pattern making
|
||||||
|
** program, whose allow create and modeling patterns of clothing.
|
||||||
|
** Copyright (C) 2018 Valentina project
|
||||||
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
||||||
|
**
|
||||||
|
** Valentina is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 3 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** Valentina is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
**
|
||||||
|
*************************************************************************/
|
||||||
|
#ifndef TST_ABSTRACTTRANSLATION_H
|
||||||
|
#define TST_ABSTRACTTRANSLATION_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
#include <QDomDocument>
|
||||||
|
|
||||||
|
class TST_AbstractTranslation : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit TST_AbstractTranslation(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QDomNodeList LoadTSFile(const QString &filename);
|
||||||
|
|
||||||
|
static const QString TagName;
|
||||||
|
static const QString TagMessage;
|
||||||
|
static const QString TagSource;
|
||||||
|
static const QString TagTranslation;
|
||||||
|
|
||||||
|
static const QString AttrType;
|
||||||
|
static const QString AttrValVanished;
|
||||||
|
static const QString AttrValUnfinished;
|
||||||
|
static const QString AttrValObsolete;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(TST_AbstractTranslation)
|
||||||
|
|
||||||
|
QSharedPointer<QFile> tsFile;
|
||||||
|
QSharedPointer<QDomDocument> tsXML;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TST_ABSTRACTTRANSLATION_H
|
319
src/test/TranslationsTest/tst_tslocaletranslation.cpp
Normal file
319
src/test/TranslationsTest/tst_tslocaletranslation.cpp
Normal file
|
@ -0,0 +1,319 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file tst_tslocaletranslation.cpp
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 17 2, 2018
|
||||||
|
**
|
||||||
|
** @brief
|
||||||
|
** @copyright
|
||||||
|
** This source code is part of the Valentina project, a pattern making
|
||||||
|
** program, whose allow create and modeling patterns of clothing.
|
||||||
|
** Copyright (C) 2018 Valentina project
|
||||||
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
||||||
|
**
|
||||||
|
** Valentina is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 3 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** Valentina is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
**
|
||||||
|
*************************************************************************/
|
||||||
|
#include "tst_tslocaletranslation.h"
|
||||||
|
|
||||||
|
#include <QtTest>
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
TST_TSLocaleTranslation::TST_TSLocaleTranslation(const QString &locale, QObject *parent)
|
||||||
|
: TST_AbstractTranslation(parent),
|
||||||
|
m_locale(locale)
|
||||||
|
{}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void TST_TSLocaleTranslation::CheckPlaceMarkerExist_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<QString>("source");
|
||||||
|
QTest::addColumn<QString>("translation");
|
||||||
|
|
||||||
|
const QString filename = QString("valentina_%1.ts").arg(m_locale);
|
||||||
|
|
||||||
|
const QDomNodeList messages = LoadTSFile(filename);
|
||||||
|
if (messages.isEmpty())
|
||||||
|
{
|
||||||
|
QFAIL("Can't begin test.");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (qint32 i = 0, num = messages.size(); i < num; ++i)
|
||||||
|
{
|
||||||
|
const QDomElement message = messages.at(i).toElement();
|
||||||
|
if (message.isNull() == false)
|
||||||
|
{
|
||||||
|
const QString source = message.firstChildElement(TagSource).text();
|
||||||
|
if (source.isEmpty())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QDomElement translationTag = message.firstChildElement(TagTranslation);
|
||||||
|
if (translationTag.hasAttribute(AttrType))
|
||||||
|
{
|
||||||
|
const QString attrVal = translationTag.attribute(AttrType);
|
||||||
|
if (attrVal == AttrValVanished || attrVal == AttrValUnfinished || attrVal == AttrValObsolete)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const QString translation = translationTag.text();
|
||||||
|
if (translation.isEmpty())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString message = QString("File '%1'. Check place holder source message '%2'").arg(filename)
|
||||||
|
.arg(source);
|
||||||
|
QTest::newRow(qUtf8Printable(message)) << source << translation;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const QString message = QString("File '%2'. Message %1 is null.").arg(i).arg(filename);
|
||||||
|
QFAIL(qUtf8Printable(message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void TST_TSLocaleTranslation::CheckPlaceMarkerExist()
|
||||||
|
{
|
||||||
|
QFETCH(QString, source);
|
||||||
|
QFETCH(QString, translation);
|
||||||
|
|
||||||
|
int sourceMarkCount = 0;
|
||||||
|
int translationMarkCount = 0;
|
||||||
|
|
||||||
|
for (int i = 1; i <= 99; ++i)
|
||||||
|
{
|
||||||
|
const QString marker = QLatin1String("%") + QString().setNum(i);
|
||||||
|
const bool sourceMark = source.indexOf(marker) != -1;
|
||||||
|
if (sourceMark)
|
||||||
|
{
|
||||||
|
++sourceMarkCount;
|
||||||
|
if (sourceMarkCount != i)
|
||||||
|
{
|
||||||
|
const QString message = QString("In source string '%1' was missed place marker ")
|
||||||
|
.arg(source) + QLatin1String("'%") + QString().setNum(sourceMarkCount) +
|
||||||
|
QLatin1String("'.");
|
||||||
|
QFAIL(qUtf8Printable(message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool translationMark = translation.indexOf(marker) != -1;
|
||||||
|
if (translationMark)
|
||||||
|
{
|
||||||
|
++translationMarkCount;
|
||||||
|
if (translationMarkCount != i)
|
||||||
|
{
|
||||||
|
const QString message = QString("In translation string '%1' was missed place marker ")
|
||||||
|
.arg(translation) + QLatin1String("'%") + QString().setNum(translationMarkCount) +
|
||||||
|
QLatin1String("'.");
|
||||||
|
QFAIL(qUtf8Printable(message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sourceMark != translationMark)
|
||||||
|
{
|
||||||
|
const QString message =
|
||||||
|
QString("Compare to source string in the translation string '%1' was missed place marker ")
|
||||||
|
.arg(translation) + QLatin1String("'%") + QString().setNum(sourceMarkCount) +
|
||||||
|
QLatin1String("'.");
|
||||||
|
QFAIL(qUtf8Printable(message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void TST_TSLocaleTranslation::TestPunctuation_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<QString>("locale");
|
||||||
|
QTest::addColumn<QString>("source");
|
||||||
|
QTest::addColumn<QString>("translation");
|
||||||
|
|
||||||
|
const QString filename = QString("valentina_%1.ts").arg(m_locale);
|
||||||
|
|
||||||
|
const QDomNodeList messages = LoadTSFile(filename);
|
||||||
|
if (messages.isEmpty())
|
||||||
|
{
|
||||||
|
QFAIL("Can't begin test.");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (qint32 i = 0, num = messages.size(); i < num; ++i)
|
||||||
|
{
|
||||||
|
const QDomElement message = messages.at(i).toElement();
|
||||||
|
if (message.isNull() == false)
|
||||||
|
{
|
||||||
|
const QString source = message.firstChildElement(TagSource).text();
|
||||||
|
if (source.isEmpty())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QDomElement translationTag = message.firstChildElement(TagTranslation);
|
||||||
|
if (translationTag.hasAttribute(AttrType))
|
||||||
|
{
|
||||||
|
const QString attrVal = translationTag.attribute(AttrType);
|
||||||
|
if (attrVal == AttrValVanished || attrVal == AttrValUnfinished || attrVal == AttrValObsolete)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const QString translation = translationTag.text();
|
||||||
|
if (translation.isEmpty())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString message = QString("File '%1'.").arg(filename);
|
||||||
|
QTest::newRow(qUtf8Printable(message)) << m_locale << source << translation;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const QString message = QString("File '%2'. Message %1 is null.").arg(i).arg(filename);
|
||||||
|
QFAIL(qUtf8Printable(message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void TST_TSLocaleTranslation::TestPunctuation()
|
||||||
|
{
|
||||||
|
QFETCH(QString, locale);
|
||||||
|
QFETCH(QString, source);
|
||||||
|
QFETCH(QString, translation);
|
||||||
|
|
||||||
|
static const QStringList punctuation = QStringList() << QLatin1String(".")
|
||||||
|
<< QLatin1String(":")
|
||||||
|
<< QLatin1String(" ")
|
||||||
|
<< QLatin1String("\n")
|
||||||
|
<< QLatin1String("!")
|
||||||
|
<< QLatin1String("?")
|
||||||
|
<< QLatin1String(";")
|
||||||
|
<< "…";
|
||||||
|
bool testFail = false;
|
||||||
|
const QChar cSource = source.at(source.length()-1);
|
||||||
|
QChar cPunctuation = cSource;
|
||||||
|
const QChar cTranslation = translation.at(translation.length()-1);
|
||||||
|
if (punctuation.contains(cSource))
|
||||||
|
{
|
||||||
|
if (not translation.endsWith(cSource))
|
||||||
|
{
|
||||||
|
testFail = true;
|
||||||
|
|
||||||
|
if (locale == QLatin1String("el_GR") && cSource == QLatin1Char('?') && cTranslation == QLatin1Char(';'))
|
||||||
|
{
|
||||||
|
testFail = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (punctuation.contains(cTranslation))
|
||||||
|
{
|
||||||
|
cPunctuation = cTranslation;
|
||||||
|
testFail = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (testFail)
|
||||||
|
{
|
||||||
|
const QString message = QString("Translation string does not end with the same punctuation character '%1' or "
|
||||||
|
"vice versa. ").arg(cPunctuation) + QString("Original name:'%1'").arg(source) +
|
||||||
|
QString(", translated name:'%1'").arg(translation);
|
||||||
|
QFAIL(qUtf8Printable(message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void TST_TSLocaleTranslation::TestHTMLTags_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<QString>("source");
|
||||||
|
QTest::addColumn<QString>("translation");
|
||||||
|
|
||||||
|
const QString filename = QString("valentina_%1.ts").arg(m_locale);
|
||||||
|
|
||||||
|
const QDomNodeList messages = LoadTSFile(filename);
|
||||||
|
if (messages.isEmpty())
|
||||||
|
{
|
||||||
|
QFAIL("Can't begin test.");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (qint32 i = 0, num = messages.size(); i < num; ++i)
|
||||||
|
{
|
||||||
|
const QDomElement message = messages.at(i).toElement();
|
||||||
|
if (message.isNull() == false)
|
||||||
|
{
|
||||||
|
const QString source = message.firstChildElement(TagSource).text();
|
||||||
|
if (source.isEmpty())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QDomElement translationTag = message.firstChildElement(TagTranslation);
|
||||||
|
if (translationTag.hasAttribute(AttrType))
|
||||||
|
{
|
||||||
|
const QString attrVal = translationTag.attribute(AttrType);
|
||||||
|
if (attrVal == AttrValVanished || attrVal == AttrValUnfinished || attrVal == AttrValObsolete)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const QString translation = translationTag.text();
|
||||||
|
if (translation.isEmpty())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString message = QString("File '%1'.").arg(filename);
|
||||||
|
QTest::newRow(qUtf8Printable(message)) << source << translation;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const QString message = QString("File '%2'. Message %1 is null.").arg(i).arg(filename);
|
||||||
|
QFAIL(qUtf8Printable(message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void TST_TSLocaleTranslation::TestHTMLTags()
|
||||||
|
{
|
||||||
|
QFETCH(QString, source);
|
||||||
|
QFETCH(QString, translation);
|
||||||
|
|
||||||
|
static const QStringList tags = QStringList() << QLatin1String("p")
|
||||||
|
<< QLatin1String("html")
|
||||||
|
<< QLatin1String("body");
|
||||||
|
static const QString pattern("{1}.*>");
|
||||||
|
for (int i=0; i < tags.size(); ++i)
|
||||||
|
{
|
||||||
|
const QRegularExpression openRegex(QLatin1String("<") + tags.at(i) + pattern,
|
||||||
|
QRegularExpression::DotMatchesEverythingOption);
|
||||||
|
if (source.contains(openRegex))
|
||||||
|
{
|
||||||
|
const int countOpenTag = source.count(openRegex);
|
||||||
|
const QRegularExpression closeRegex(QLatin1String("</") + tags.at(i) + pattern,
|
||||||
|
QRegularExpression::DotMatchesEverythingOption);
|
||||||
|
const int countCloseTag = translation.count(closeRegex);
|
||||||
|
if (not translation.contains(closeRegex) || countCloseTag != countOpenTag)
|
||||||
|
{
|
||||||
|
const QString message = QString("Tag mismatch. Tag: '<%1>'. ").arg(tags.at(i)) +
|
||||||
|
QString("Original name:'%1'").arg(source) + QString(", translated name:'%1'").arg(translation);
|
||||||
|
QFAIL(qUtf8Printable(message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
53
src/test/TranslationsTest/tst_tslocaletranslation.h
Normal file
53
src/test/TranslationsTest/tst_tslocaletranslation.h
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file tst_tslocaletranslation.h
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 17 2, 2018
|
||||||
|
**
|
||||||
|
** @brief
|
||||||
|
** @copyright
|
||||||
|
** This source code is part of the Valentina project, a pattern making
|
||||||
|
** program, whose allow create and modeling patterns of clothing.
|
||||||
|
** Copyright (C) 2018 Valentina project
|
||||||
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
||||||
|
**
|
||||||
|
** Valentina is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 3 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** Valentina is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
**
|
||||||
|
*************************************************************************/
|
||||||
|
#ifndef TST_TSLOCALETRANSLATION_H
|
||||||
|
#define TST_TSLOCALETRANSLATION_H
|
||||||
|
|
||||||
|
#include "tst_abstracttranslation.h"
|
||||||
|
|
||||||
|
class TST_TSLocaleTranslation : public TST_AbstractTranslation
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit TST_TSLocaleTranslation(const QString &locale, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void CheckPlaceMarkerExist_data();
|
||||||
|
void CheckPlaceMarkerExist();
|
||||||
|
void TestPunctuation_data();
|
||||||
|
void TestPunctuation();
|
||||||
|
void TestHTMLTags_data();
|
||||||
|
void TestHTMLTags();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(TST_TSLocaleTranslation)
|
||||||
|
|
||||||
|
QString m_locale;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TST_TSLOCALETRANSLATION_H
|
|
@ -35,23 +35,10 @@
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(QDomElement) // Need for testing
|
Q_DECLARE_METATYPE(QDomElement) // Need for testing
|
||||||
|
|
||||||
const QString TST_TSTranslation::TagName = QStringLiteral("name");
|
|
||||||
const QString TST_TSTranslation::TagMessage = QStringLiteral("message");
|
|
||||||
const QString TST_TSTranslation::TagSource = QStringLiteral("source");
|
|
||||||
const QString TST_TSTranslation::TagTranslation = QStringLiteral("translation");
|
|
||||||
|
|
||||||
const QString TST_TSTranslation::AttrType = QStringLiteral("type");
|
|
||||||
const QString TST_TSTranslation::AttrValVanished = QStringLiteral("vanished");
|
|
||||||
const QString TST_TSTranslation::AttrValUnfinished = QStringLiteral("unfinished");
|
|
||||||
const QString TST_TSTranslation::AttrValObsolete = QStringLiteral("obsolete");
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
TST_TSTranslation::TST_TSTranslation(QObject *parent)
|
TST_TSTranslation::TST_TSTranslation(QObject *parent)
|
||||||
: QObject(parent),
|
: TST_AbstractTranslation(parent)
|
||||||
tsFile(),
|
{}
|
||||||
tsXML()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void TST_TSTranslation::CheckEnglishLocalization_data()
|
void TST_TSTranslation::CheckEnglishLocalization_data()
|
||||||
|
@ -149,322 +136,6 @@ void TST_TSTranslation::CheckEmptyToolButton()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
void TST_TSTranslation::CheckPlaceMarkerExist_data()
|
|
||||||
{
|
|
||||||
const QStringList locales = SupportedLocales();
|
|
||||||
|
|
||||||
{
|
|
||||||
QDir dir(TS_DIR);
|
|
||||||
const QStringList fileNames = dir.entryList(QStringList("valentina*.ts"));
|
|
||||||
QVERIFY2(locales.size() == fileNames.size()-1, "Unexpected count of files.");
|
|
||||||
}
|
|
||||||
|
|
||||||
QTest::addColumn<QString>("source");
|
|
||||||
QTest::addColumn<QString>("translation");
|
|
||||||
|
|
||||||
for(int j = 0; j < locales.size(); ++j)
|
|
||||||
{
|
|
||||||
const QString filename = QString("valentina_%1.ts").arg(locales.at(j));
|
|
||||||
|
|
||||||
const QDomNodeList messages = LoadTSFile(filename);
|
|
||||||
if (messages.isEmpty())
|
|
||||||
{
|
|
||||||
QFAIL("Can't begin test.");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (qint32 i = 0, num = messages.size(); i < num; ++i)
|
|
||||||
{
|
|
||||||
const QDomElement message = messages.at(i).toElement();
|
|
||||||
if (message.isNull() == false)
|
|
||||||
{
|
|
||||||
const QString source = message.firstChildElement(TagSource).text();
|
|
||||||
if (source.isEmpty())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QDomElement translationTag = message.firstChildElement(TagTranslation);
|
|
||||||
if (translationTag.hasAttribute(AttrType))
|
|
||||||
{
|
|
||||||
const QString attrVal = translationTag.attribute(AttrType);
|
|
||||||
if (attrVal == AttrValVanished || attrVal == AttrValUnfinished || attrVal == AttrValObsolete)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const QString translation = translationTag.text();
|
|
||||||
if (translation.isEmpty())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString message = QString("File '%1'. Check place holder source message '%2'").arg(filename)
|
|
||||||
.arg(source);
|
|
||||||
QTest::newRow(qUtf8Printable(message)) << source << translation;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const QString message = QString("File '%2'. Message %1 is null.").arg(i).arg(filename);
|
|
||||||
QFAIL(qUtf8Printable(message));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
void TST_TSTranslation::CheckPlaceMarkerExist()
|
|
||||||
{
|
|
||||||
QFETCH(QString, source);
|
|
||||||
QFETCH(QString, translation);
|
|
||||||
|
|
||||||
int sourceMarkCount = 0;
|
|
||||||
int translationMarkCount = 0;
|
|
||||||
|
|
||||||
for (int i = 1; i <= 99; ++i)
|
|
||||||
{
|
|
||||||
const QString marker = QLatin1String("%") + QString().setNum(i);
|
|
||||||
const bool sourceMark = source.indexOf(marker) != -1;
|
|
||||||
if (sourceMark)
|
|
||||||
{
|
|
||||||
++sourceMarkCount;
|
|
||||||
if (sourceMarkCount != i)
|
|
||||||
{
|
|
||||||
const QString message = QString("In source string '%1' was missed place marker ")
|
|
||||||
.arg(source) + QLatin1String("'%") + QString().setNum(sourceMarkCount) +
|
|
||||||
QLatin1String("'.");
|
|
||||||
QFAIL(qUtf8Printable(message));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool translationMark = translation.indexOf(marker) != -1;
|
|
||||||
if (translationMark)
|
|
||||||
{
|
|
||||||
++translationMarkCount;
|
|
||||||
if (translationMarkCount != i)
|
|
||||||
{
|
|
||||||
const QString message = QString("In translation string '%1' was missed place marker ")
|
|
||||||
.arg(translation) + QLatin1String("'%") + QString().setNum(translationMarkCount) +
|
|
||||||
QLatin1String("'.");
|
|
||||||
QFAIL(qUtf8Printable(message));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sourceMark != translationMark)
|
|
||||||
{
|
|
||||||
const QString message =
|
|
||||||
QString("Compare to source string in the translation string '%1' was missed place marker ")
|
|
||||||
.arg(translation) + QLatin1String("'%") + QString().setNum(sourceMarkCount) +
|
|
||||||
QLatin1String("'.");
|
|
||||||
QFAIL(qUtf8Printable(message));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
void TST_TSTranslation::TestPunctuation_data()
|
|
||||||
{
|
|
||||||
const QStringList locales = SupportedLocales();
|
|
||||||
|
|
||||||
{
|
|
||||||
QDir dir(TS_DIR);
|
|
||||||
const QStringList fileNames = dir.entryList(QStringList("valentina*.ts"));
|
|
||||||
QVERIFY2(locales.size() == fileNames.size()-1, "Unexpected count of files.");
|
|
||||||
}
|
|
||||||
|
|
||||||
QTest::addColumn<QString>("locale");
|
|
||||||
QTest::addColumn<QString>("source");
|
|
||||||
QTest::addColumn<QString>("translation");
|
|
||||||
|
|
||||||
for(int j = 0; j < locales.size(); ++j)
|
|
||||||
{
|
|
||||||
const QString filename = QString("valentina_%1.ts").arg(locales.at(j));
|
|
||||||
|
|
||||||
const QDomNodeList messages = LoadTSFile(filename);
|
|
||||||
if (messages.isEmpty())
|
|
||||||
{
|
|
||||||
QFAIL("Can't begin test.");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (qint32 i = 0, num = messages.size(); i < num; ++i)
|
|
||||||
{
|
|
||||||
const QDomElement message = messages.at(i).toElement();
|
|
||||||
if (message.isNull() == false)
|
|
||||||
{
|
|
||||||
const QString source = message.firstChildElement(TagSource).text();
|
|
||||||
if (source.isEmpty())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QDomElement translationTag = message.firstChildElement(TagTranslation);
|
|
||||||
if (translationTag.hasAttribute(AttrType))
|
|
||||||
{
|
|
||||||
const QString attrVal = translationTag.attribute(AttrType);
|
|
||||||
if (attrVal == AttrValVanished || attrVal == AttrValUnfinished || attrVal == AttrValObsolete)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const QString translation = translationTag.text();
|
|
||||||
if (translation.isEmpty())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString message = QString("File '%1'.").arg(filename);
|
|
||||||
QTest::newRow(qUtf8Printable(message)) << locales.at(j) << source << translation;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const QString message = QString("File '%2'. Message %1 is null.").arg(i).arg(filename);
|
|
||||||
QFAIL(qUtf8Printable(message));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
void TST_TSTranslation::TestPunctuation()
|
|
||||||
{
|
|
||||||
QFETCH(QString, locale);
|
|
||||||
QFETCH(QString, source);
|
|
||||||
QFETCH(QString, translation);
|
|
||||||
|
|
||||||
static const QStringList punctuation = QStringList() << QLatin1String(".")
|
|
||||||
<< QLatin1String(":")
|
|
||||||
<< QLatin1String(" ")
|
|
||||||
<< QLatin1String("\n")
|
|
||||||
<< QLatin1String("!")
|
|
||||||
<< QLatin1String("?")
|
|
||||||
<< QLatin1String(";")
|
|
||||||
<< "…";
|
|
||||||
bool testFail = false;
|
|
||||||
const QChar cSource = source.at(source.length()-1);
|
|
||||||
QChar cPunctuation = cSource;
|
|
||||||
const QChar cTranslation = translation.at(translation.length()-1);
|
|
||||||
if (punctuation.contains(cSource))
|
|
||||||
{
|
|
||||||
if (not translation.endsWith(cSource))
|
|
||||||
{
|
|
||||||
testFail = true;
|
|
||||||
|
|
||||||
if (locale == QLatin1String("el_GR") && cSource == QLatin1Char('?') && cTranslation == QLatin1Char(';'))
|
|
||||||
{
|
|
||||||
testFail = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (punctuation.contains(cTranslation))
|
|
||||||
{
|
|
||||||
cPunctuation = cTranslation;
|
|
||||||
testFail = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (testFail)
|
|
||||||
{
|
|
||||||
const QString message = QString("Translation string does not end with the same punctuation character '%1' or "
|
|
||||||
"vice versa. ").arg(cPunctuation) + QString("Original name:'%1'").arg(source) +
|
|
||||||
QString(", translated name:'%1'").arg(translation);
|
|
||||||
QFAIL(qUtf8Printable(message));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
void TST_TSTranslation::TestHTMLTags_data()
|
|
||||||
{
|
|
||||||
const QStringList locales = SupportedLocales();
|
|
||||||
|
|
||||||
{
|
|
||||||
QDir dir(TS_DIR);
|
|
||||||
const QStringList fileNames = dir.entryList(QStringList("valentina*.ts"));
|
|
||||||
QVERIFY2(locales.size() == fileNames.size()-1, "Unexpected count of files.");
|
|
||||||
}
|
|
||||||
|
|
||||||
QTest::addColumn<QString>("source");
|
|
||||||
QTest::addColumn<QString>("translation");
|
|
||||||
|
|
||||||
for(int j = 0; j < locales.size(); ++j)
|
|
||||||
{
|
|
||||||
const QString filename = QString("valentina_%1.ts").arg(locales.at(j));
|
|
||||||
|
|
||||||
const QDomNodeList messages = LoadTSFile(filename);
|
|
||||||
if (messages.isEmpty())
|
|
||||||
{
|
|
||||||
QFAIL("Can't begin test.");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (qint32 i = 0, num = messages.size(); i < num; ++i)
|
|
||||||
{
|
|
||||||
const QDomElement message = messages.at(i).toElement();
|
|
||||||
if (message.isNull() == false)
|
|
||||||
{
|
|
||||||
const QString source = message.firstChildElement(TagSource).text();
|
|
||||||
if (source.isEmpty())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QDomElement translationTag = message.firstChildElement(TagTranslation);
|
|
||||||
if (translationTag.hasAttribute(AttrType))
|
|
||||||
{
|
|
||||||
const QString attrVal = translationTag.attribute(AttrType);
|
|
||||||
if (attrVal == AttrValVanished || attrVal == AttrValUnfinished || attrVal == AttrValObsolete)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const QString translation = translationTag.text();
|
|
||||||
if (translation.isEmpty())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString message = QString("File '%1'.").arg(filename);
|
|
||||||
QTest::newRow(qUtf8Printable(message)) << source << translation;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const QString message = QString("File '%2'. Message %1 is null.").arg(i).arg(filename);
|
|
||||||
QFAIL(qUtf8Printable(message));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
void TST_TSTranslation::TestHTMLTags()
|
|
||||||
{
|
|
||||||
QFETCH(QString, source);
|
|
||||||
QFETCH(QString, translation);
|
|
||||||
|
|
||||||
static const QStringList tags = QStringList() << QLatin1String("p")
|
|
||||||
<< QLatin1String("html")
|
|
||||||
<< QLatin1String("body");
|
|
||||||
static const QString pattern("{1}.*>");
|
|
||||||
for (int i=0; i < tags.size(); ++i)
|
|
||||||
{
|
|
||||||
const QRegularExpression openRegex(QLatin1String("<") + tags.at(i) + pattern,
|
|
||||||
QRegularExpression::DotMatchesEverythingOption);
|
|
||||||
if (source.contains(openRegex))
|
|
||||||
{
|
|
||||||
const int countOpenTag = source.count(openRegex);
|
|
||||||
const QRegularExpression closeRegex(QLatin1String("</") + tags.at(i) + pattern,
|
|
||||||
QRegularExpression::DotMatchesEverythingOption);
|
|
||||||
const int countCloseTag = translation.count(closeRegex);
|
|
||||||
if (not translation.contains(closeRegex) || countCloseTag != countOpenTag)
|
|
||||||
{
|
|
||||||
const QString message = QString("Tag mismatch. Tag: '<%1>'. ").arg(tags.at(i)) +
|
|
||||||
QString("Original name:'%1'").arg(source) + QString(", translated name:'%1'").arg(translation);
|
|
||||||
QFAIL(qUtf8Printable(message));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void TST_TSTranslation::CheckEllipsis_data()
|
void TST_TSTranslation::CheckEllipsis_data()
|
||||||
{
|
{
|
||||||
|
@ -502,48 +173,6 @@ void TST_TSTranslation::CheckEllipsis()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
QDomNodeList TST_TSTranslation::LoadTSFile(const QString &filename)
|
|
||||||
{
|
|
||||||
tsFile.reset();
|
|
||||||
tsFile = QSharedPointer<QFile>(new QFile(QString("%1/%2").arg(TS_DIR).arg(filename)));
|
|
||||||
if (not tsFile->exists())
|
|
||||||
{
|
|
||||||
const QString message = QString("Can't find '%1'.\n%2.").arg(filename).arg(tsFile->errorString());
|
|
||||||
QWARN(qUtf8Printable(message));
|
|
||||||
return QDomNodeList();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tsFile->open(QIODevice::ReadOnly) == false)
|
|
||||||
{
|
|
||||||
const QString message = QString("Can't open file '%1'.\n%2.").arg(filename).arg(tsFile->errorString());
|
|
||||||
QWARN(qUtf8Printable(message));
|
|
||||||
return QDomNodeList();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString errorMsg;
|
|
||||||
int errorLine = -1;
|
|
||||||
int errorColumn = -1;
|
|
||||||
tsXML.reset();
|
|
||||||
tsXML = QSharedPointer<QDomDocument>(new QDomDocument());
|
|
||||||
if (tsXML->setContent(tsFile.data(), &errorMsg, &errorLine, &errorColumn) == false)
|
|
||||||
{
|
|
||||||
const QString message = QString("Parsing error file %1 in line %2 column %3.")
|
|
||||||
.arg(filename).arg(errorLine).arg(errorColumn);
|
|
||||||
QWARN(qUtf8Printable(message));
|
|
||||||
return QDomNodeList();
|
|
||||||
}
|
|
||||||
|
|
||||||
const QDomNodeList messages = tsXML->elementsByTagName(TagMessage);
|
|
||||||
if (messages.isEmpty())
|
|
||||||
{
|
|
||||||
QWARN("File doesn't contain any messages.");
|
|
||||||
return QDomNodeList();
|
|
||||||
}
|
|
||||||
|
|
||||||
return messages;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void TST_TSTranslation::PrepareOriginalStrings()
|
void TST_TSTranslation::PrepareOriginalStrings()
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,12 +29,9 @@
|
||||||
#ifndef TST_TSTRANSLATION_H
|
#ifndef TST_TSTRANSLATION_H
|
||||||
#define TST_TSTRANSLATION_H
|
#define TST_TSTRANSLATION_H
|
||||||
|
|
||||||
#include <QDomDocument>
|
#include "tst_abstracttranslation.h"
|
||||||
#include <QFile>
|
|
||||||
#include <QObject>
|
|
||||||
#include <QSharedPointer>
|
|
||||||
|
|
||||||
class TST_TSTranslation : public QObject
|
class TST_TSTranslation : public TST_AbstractTranslation
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -45,31 +42,11 @@ private slots:
|
||||||
void CheckEnglishLocalization();
|
void CheckEnglishLocalization();
|
||||||
void CheckEmptyToolButton_data();
|
void CheckEmptyToolButton_data();
|
||||||
void CheckEmptyToolButton();
|
void CheckEmptyToolButton();
|
||||||
void CheckPlaceMarkerExist_data();
|
|
||||||
void CheckPlaceMarkerExist();
|
|
||||||
void TestPunctuation_data();
|
|
||||||
void TestPunctuation();
|
|
||||||
void TestHTMLTags_data();
|
|
||||||
void TestHTMLTags();
|
|
||||||
void CheckEllipsis_data();
|
void CheckEllipsis_data();
|
||||||
void CheckEllipsis();
|
void CheckEllipsis();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(TST_TSTranslation)
|
Q_DISABLE_COPY(TST_TSTranslation)
|
||||||
QSharedPointer<QFile> tsFile;
|
|
||||||
QSharedPointer<QDomDocument> tsXML;
|
|
||||||
|
|
||||||
static const QString TagName;
|
|
||||||
static const QString TagMessage;
|
|
||||||
static const QString TagSource;
|
|
||||||
static const QString TagTranslation;
|
|
||||||
|
|
||||||
static const QString AttrType;
|
|
||||||
static const QString AttrValVanished;
|
|
||||||
static const QString AttrValUnfinished;
|
|
||||||
static const QString AttrValObsolete;
|
|
||||||
|
|
||||||
QDomNodeList LoadTSFile(const QString &filename);
|
|
||||||
|
|
||||||
void PrepareOriginalStrings();
|
void PrepareOriginalStrings();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user