Fix resolving resources when running from build directory

* Copy wordlists to build dir share folder
* Change resource path resolution to only test the provided directory, not finding a specific file
This commit is contained in:
Jonathan White
2020-06-04 08:16:47 -04:00
parent c830f85c09
commit 6f5e13815c
5 changed files with 40 additions and 56 deletions

View File

@@ -49,22 +49,9 @@ void Translator::installTranslators()
// Always try to load english last
languages << "en_US";
const QStringList paths = {
#ifdef QT_DEBUG
QString("%1/share/translations").arg(KEEPASSX_BINARY_DIR),
#endif
resources()->dataPath("translations")};
bool translationsLoaded = false;
for (const QString& path : paths) {
installQtTranslator(languages, path);
if (installTranslator(languages, path)) {
translationsLoaded = true;
break;
}
}
if (!translationsLoaded) {
const auto path = resources()->dataPath("translations");
installQtTranslator(languages, path);
if (!installTranslator(languages, path)) {
// couldn't load configured language or fallback
qWarning("Couldn't load translations.");
}
@@ -117,40 +104,31 @@ bool Translator::installQtTranslator(const QStringList& languages, const QString
*/
QList<QPair<QString, QString>> Translator::availableLanguages()
{
const QStringList paths = {
#ifdef QT_DEBUG
QString("%1/share/translations").arg(KEEPASSX_BINARY_DIR),
#endif
resources()->dataPath("translations")};
QList<QPair<QString, QString>> languages;
languages.append(QPair<QString, QString>("system", "System default"));
QRegularExpression regExp("^keepassx_([a-zA-Z_]+)\\.qm$", QRegularExpression::CaseInsensitiveOption);
for (const QString& path : paths) {
const QStringList fileList = QDir(path).entryList();
for (const QString& filename : fileList) {
QRegularExpressionMatch match = regExp.match(filename);
if (match.hasMatch()) {
QString langcode = match.captured(1);
if (langcode == "en") {
continue;
}
QLocale locale(langcode);
QString languageStr = QLocale::languageToString(locale.language());
if (langcode == "la") {
// langcode "la" (Latin) is translated into "C" by QLocale::languageToString()
languageStr = "Latin";
}
QString countryStr;
if (langcode.contains("_")) {
countryStr = QString(" (%1)").arg(QLocale::countryToString(locale.country()));
}
QPair<QString, QString> language(langcode, languageStr + countryStr);
languages.append(language);
const QStringList fileList = QDir(resources()->dataPath("translations")).entryList();
for (const QString& filename : fileList) {
QRegularExpressionMatch match = regExp.match(filename);
if (match.hasMatch()) {
QString langcode = match.captured(1);
if (langcode == "en") {
continue;
}
QLocale locale(langcode);
QString languageStr = QLocale::languageToString(locale.language());
if (langcode == "la") {
// langcode "la" (Latin) is translated into "C" by QLocale::languageToString()
languageStr = "Latin";
}
if (langcode.contains("_")) {
languageStr += QString(" (%1)").arg(QLocale::countryToString(locale.country()));
}
QPair<QString, QString> language(langcode, languageStr);
languages.append(language);
}
}