diff --git a/src/generator/main.cpp b/src/generator/main.cpp --- a/src/generator/main.cpp +++ b/src/generator/main.cpp @@ -117,17 +117,23 @@ static const char country_name_stringtable[] = { )"); - const QHash parsedList = TranslatedCountries::parseFilesRecursive(sourceDirPath); + const auto parsedList = TranslatedCountries::parseFilesRecursive(sourceDirPath); struct Elem { QByteArray name; QString isoCode; + QString language; int offset; }; std::vector processedList; processedList.reserve(parsedList.size()); - for(auto it = parsedList.begin() ; it != parsedList.end() ; it++) { - processedList.push_back(Elem{it.key().toCaseFolded().toUtf8(), it.value(), 0}); + for(const auto &country : parsedList) { + const auto name = country.name.toCaseFolded().toUtf8(); + if (name.isEmpty()) { + qWarning() << "Skipping empty normalized country name:" << country.name << country.isoCode << country.language; + continue; + } + processedList.push_back(Elem{name, country.isoCode, country.language, 0}); } // we must sort exactly as we do this for lookup std::sort(processedList.begin(), processedList.end(), [](const Elem &lhs, const Elem &rhs) { @@ -150,7 +156,9 @@ ++it; continue; } - qDebug() << "Removing ambigious string:" << QString::fromUtf8((*it).name) << (*prevIt).isoCode << (*it).isoCode; + qDebug() << "Removing ambigious string:" << QString::fromUtf8((*it).name) + << (*prevIt).isoCode.toUpper() << (*prevIt).language + << (*it).isoCode.toUpper() << (*it).language; it = processedList.erase(prevIt); it = processedList.erase(it); } diff --git a/src/generator/translatedcountrylist.h b/src/generator/translatedcountrylist.h --- a/src/generator/translatedcountrylist.h +++ b/src/generator/translatedcountrylist.h @@ -25,22 +25,22 @@ #ifndef TRANSLATEDCOUNTRYLIST_H #define TRANSLATEDCOUNTRYLIST_H -#include #include + +#include + class QIODevice; namespace TranslatedCountries { - using TranslationCountryMap = QHash; - /** - * \param device open QIODevice to read cldr xml data from - * \return map of translation name => country id - */ - TranslationCountryMap parseFile(QIODevice *device); - /** - * \param filePath path to read cldr xml file - * \return map of translation name => country id - */ - TranslationCountryMap parseFilePath(const QString &filePath); + + struct CountryNameMapping { + QString name; + QString isoCode; + QString language; + }; + + using TranslationCountryMap = std::vector; + /** * \param directoryPath directory path to scan recursively for cldr xml files * On Debian systems, /usr/share/unicode/cldr/common/main is a good value for this. diff --git a/src/generator/translatedcountrylist.cpp b/src/generator/translatedcountrylist.cpp --- a/src/generator/translatedcountrylist.cpp +++ b/src/generator/translatedcountrylist.cpp @@ -26,13 +26,13 @@ #include "translatedcountrylist.h" -#include +#include #include +#include #include -TranslatedCountries::TranslationCountryMap TranslatedCountries::parseFile(QIODevice *device) +static void parseFile(QIODevice *device, const QString &lang, TranslatedCountries::TranslationCountryMap &map) { - TranslationCountryMap map; QXmlStreamReader reader(device); const QStringList blacklist = { QLatin1String("eu"), QLatin1String("un"), QLatin1String("zz") }; while(!reader.atEnd()) { @@ -46,25 +46,25 @@ } const auto name = reader.readElementText(); if (!name.isEmpty()) { - map.insert(name, territory); + map.push_back({name, territory, lang}); } } break; default: break; } } - return map; } -TranslatedCountries::TranslationCountryMap TranslatedCountries::parseFilePath(const QString &filePath) +static void parseFilePath(const QString &filePath, TranslatedCountries::TranslationCountryMap &map) { QFile f(filePath); bool success = f.open(QIODevice::ReadOnly); if (!success) { - return {}; + qWarning() << "Failed to open" << f.fileName() << f.errorString(); + return; } - return parseFile(&f); + return parseFile(&f, QFileInfo(filePath).baseName(), map); } TranslatedCountries::TranslationCountryMap TranslatedCountries::parseFilesRecursive(const QString &directoryPath) @@ -74,7 +74,7 @@ while (it.hasNext()) { it.next(); QString path = it.filePath(); - map.unite(parseFilePath(path)); + parseFilePath(path, map); } return map; }