Skip to content

Commit

Permalink
Refactor load/install translators
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Lamar committed Mar 9, 2024
1 parent bde4be3 commit dd4ddcf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/kiwixapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,20 @@ KiwixApp::KiwixApp(int& argc, char *argv[])
return;
}

bool loaded = false;
bool installed = false;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
loaded = m_qtTranslator.load(QLocale(), "qt", "_",
QLibraryInfo::location(QLibraryInfo::TranslationsPath));
QString path = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
#else
loaded = m_qtTranslator.load(QLocale(), "qt", "_",
QLibraryInfo::path(QLibraryInfo::TranslationsPath));
QString path = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
#endif
if (loaded) {
installed = installTranslator(&m_qtTranslator);
if (!installed) {
// ignore for now
}
bool success = false;
success = loadAndInstallTranslations(m_qtTranslator, "qt", path);
if (!success) {
// ignore for now
}

loaded = m_appTranslator.load(QLocale(), "kiwix-desktop", "_", ":/i18n/");
if (loaded) {
installed = installTranslator(&m_appTranslator);
if (!installed) {
// ignore for now
}
success = loadAndInstallTranslations(m_appTranslator, "kiwix-desktop", ":/i18n/");
if (!success) {
// ignore for now
}

QFontDatabase::addApplicationFont(":/fonts/Selawik/selawkb.ttf");
Expand All @@ -73,6 +65,16 @@ KiwixApp::KiwixApp(int& argc, char *argv[])
setFont(QFont("Selawik"));
}

bool KiwixApp::loadAndInstallTranslations(QTranslator& translator, const QString& filename, const QString& directory) {
bool loaded = false;

loaded = translator.load(QLocale(), filename, "_", directory);
if (loaded) {
return installTranslator(&translator);
}
return false;
}

void KiwixApp::init()
{
try {
Expand Down
1 change: 1 addition & 0 deletions src/kiwixapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public slots:
QAction* mpa_actions[MAX_ACTION];

QString findLibraryDirectory();
bool loadAndInstallTranslations(QTranslator& translator, const QString& filename, const QString& directory);
};

QString gt(const QString &key);
Expand Down

0 comments on commit dd4ddcf

Please sign in to comment.