You've already forked translationStats
147 lines
4.1 KiB
C++
147 lines
4.1 KiB
C++
#include "StatsData.h"
|
|
|
|
#include <QCoreApplication>
|
|
#include <QDirIterator>
|
|
#include <QXmlStreamReader>
|
|
#include <QTimer>
|
|
|
|
StatsData::StatsData(const QString &dir)
|
|
: m_dir(dir)
|
|
{
|
|
QTimer::singleShot(10, this, SLOT(start()));
|
|
}
|
|
|
|
static bool sortByMobileFinished(const QObject *a, const QObject *b)
|
|
{
|
|
const auto *row1 = qobject_cast<const Row*>(a);
|
|
const auto *row2 = qobject_cast<const Row*>(b);
|
|
assert(row1);
|
|
assert(row2);
|
|
|
|
return row1->doneMobile() > row2->doneMobile();
|
|
}
|
|
|
|
void StatsData::start()
|
|
{
|
|
struct Language {
|
|
int desktopStrings = 0;
|
|
int desktopDone = 0;
|
|
int mobileStrings = 0;
|
|
int mobileDone = 0;
|
|
};
|
|
QHash<QString, Language> stats;
|
|
|
|
QDirIterator iter(m_dir);
|
|
while (iter.hasNext()) {
|
|
auto filePath = iter.next();
|
|
if (filePath.length() > 6 && filePath.endsWith(".ts") && filePath.at(filePath.size() - 6) == '_') {
|
|
int slash = filePath.lastIndexOf('/');
|
|
QString filename(filePath);
|
|
if (slash != -1)
|
|
filename = filePath.mid(slash + 1);
|
|
QString lang = filename.mid(filename.size() - 5, 2);
|
|
QFile data(filePath);
|
|
if (!data.open(QIODevice::ReadOnly)) {
|
|
qWarning() << "Failed to read" << filename;
|
|
continue;
|
|
}
|
|
auto bytes = data.readAll();
|
|
data.close();
|
|
int strings = 0;
|
|
int translated = 0;
|
|
QXmlStreamReader reader(bytes);
|
|
while (!reader.atEnd()) {
|
|
if (reader.readNextStartElement() && reader.name().compare("translation", Qt::CaseSensitive) == 0) {
|
|
++strings;
|
|
auto attributes = reader.attributes();
|
|
auto type = attributes.value("type");
|
|
if (type.isNull() || type.compare("unfinished", Qt::CaseSensitive) != 0)
|
|
++translated;
|
|
}
|
|
}
|
|
|
|
Language &language = stats[lang];
|
|
if (filename.startsWith("floweepay-common_")) {
|
|
language.desktopDone += translated;
|
|
language.desktopStrings += strings;
|
|
language.mobileDone += translated;
|
|
language.mobileStrings += strings;
|
|
}
|
|
else if (filename.startsWith("floweepay-desktop_")) {
|
|
language.desktopDone += translated;
|
|
language.desktopStrings += strings;
|
|
} else if (filename.startsWith("floweepay-mobile_")
|
|
|| filename.startsWith("module-build-transaction_")
|
|
|| filename.startsWith("module-peers-view_")
|
|
|| filename.startsWith("module-send-sweep_")
|
|
) {
|
|
language.mobileDone += translated;
|
|
language.mobileStrings += strings;
|
|
}
|
|
}
|
|
}
|
|
|
|
for (const auto &key : stats.keys()) {
|
|
auto language = stats.value(key);
|
|
auto *row = new Row(key, this);
|
|
m_rows.append(row);
|
|
|
|
row->m_mobileStringCount = language.mobileStrings;
|
|
row->m_desktopStringCount = language.desktopStrings;
|
|
row->m_doneMobile = language.mobileDone;
|
|
row->m_doneDesktop = language.desktopDone;
|
|
}
|
|
std::sort(m_rows.begin(), m_rows.end(), sortByMobileFinished);
|
|
emit rowsChanged();
|
|
}
|
|
|
|
QList<QObject *> StatsData::rows() const
|
|
{
|
|
return m_rows;
|
|
}
|
|
|
|
Row::Row(const QString &language, QObject *parent)
|
|
: QObject(parent),
|
|
m_language(language)
|
|
{
|
|
|
|
}
|
|
|
|
QString Row::language() const
|
|
{
|
|
if (m_language == "de")
|
|
return "Deutsch";
|
|
if (m_language == "nl")
|
|
return "Dutch";
|
|
if (m_language == "pl")
|
|
return "Polski";
|
|
if (m_language == "es")
|
|
return "Español";
|
|
if (m_language == "ha")
|
|
return "Hausa";
|
|
if (m_language == "pt")
|
|
return "pt_BR";
|
|
|
|
return m_language;
|
|
}
|
|
|
|
int Row::mobileStringCount() const
|
|
{
|
|
return m_mobileStringCount;
|
|
}
|
|
|
|
int Row::desktopStringCount() const
|
|
{
|
|
return m_desktopStringCount;
|
|
}
|
|
|
|
int Row::doneMobile() const
|
|
{
|
|
return m_doneMobile;
|
|
}
|
|
|
|
int Row::doneDesktop() const
|
|
{
|
|
return m_doneDesktop;
|
|
}
|