mirror of https://github.com/OpenMW/openmw.git
Deploy base Qt translations when needed
parent
66b2d428c8
commit
9a7b9572fd
@ -0,0 +1,37 @@
|
||||
#include "qttranslations.hpp"
|
||||
|
||||
#include <QLibraryInfo>
|
||||
#include <QLocale>
|
||||
|
||||
namespace l10n
|
||||
{
|
||||
QTranslator AppTranslator{};
|
||||
QTranslator ComponentsTranslator{};
|
||||
QTranslator QtBaseAppTranslator{};
|
||||
|
||||
void installQtTranslations(QApplication& app, const QString& appName, const QString& resourcesPath)
|
||||
{
|
||||
// Try to load OpenMW translations from resources folder first.
|
||||
// If we loaded them, try to load Qt translations from both
|
||||
// resources folder and default translations folder as well.
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
auto qtPath = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
|
||||
#else
|
||||
auto qtPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
|
||||
#endif
|
||||
auto localPath = resourcesPath + "/translations";
|
||||
|
||||
if (AppTranslator.load(QLocale::system(), appName, "_", localPath)
|
||||
&& ComponentsTranslator.load(QLocale::system(), "components", "_", localPath))
|
||||
{
|
||||
app.installTranslator(&AppTranslator);
|
||||
app.installTranslator(&ComponentsTranslator);
|
||||
|
||||
if (QtBaseAppTranslator.load(QLocale::system(), "qtbase", "_", localPath)
|
||||
|| QtBaseAppTranslator.load(QLocale::system(), "qt", "_", localPath)
|
||||
|| QtBaseAppTranslator.load(QLocale::system(), "qtbase", "_", qtPath)
|
||||
|| QtBaseAppTranslator.load(QLocale::system(), "qt", "_", qtPath))
|
||||
app.installTranslator(&QtBaseAppTranslator);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
#ifndef COMPONENTS_L10N_QTTRANSLATIONS_H
|
||||
#define COMPONENTS_L10N_QTTRANSLATIONS_H
|
||||
|
||||
#include <QApplication>
|
||||
#include <QTranslator>
|
||||
|
||||
namespace l10n
|
||||
{
|
||||
extern QTranslator AppTranslator;
|
||||
extern QTranslator ComponentsTranslator;
|
||||
extern QTranslator QtBaseAppTranslator;
|
||||
|
||||
void installQtTranslations(QApplication& app, const QString& appName, const QString& resourcesPath);
|
||||
}
|
||||
|
||||
#endif // COMPONENTS_L10N_QTTRANSLATIONS_H
|
Loading…
Reference in New Issue