Add translation search path in resources
This commit is contained in:
parent
1757b2b89f
commit
d7cb1e3f56
@ -1,16 +1,9 @@
|
|||||||
#include "apptranslator.h"
|
#include "apptranslator.h"
|
||||||
#include "debug.h"
|
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDir>
|
|
||||||
#include <QLibraryInfo>
|
#include <QLibraryInfo>
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
// const auto builtin = QLocale::English;
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
AppTranslator::AppTranslator(const QStringList &translationFiles)
|
AppTranslator::AppTranslator(const QStringList &translationFiles)
|
||||||
: translationFiles_(translationFiles)
|
: translationFiles_(translationFiles)
|
||||||
{
|
{
|
||||||
@ -24,7 +17,6 @@ void AppTranslator::retranslate()
|
|||||||
old->deleteLater();
|
old->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
// QLocale locale(translation());
|
|
||||||
QLocale locale;
|
QLocale locale;
|
||||||
const auto files =
|
const auto files =
|
||||||
QStringList{QStringLiteral("qt"), QStringLiteral("qtbase")} +
|
QStringList{QStringLiteral("qt"), QStringLiteral("qtbase")} +
|
||||||
@ -44,63 +36,6 @@ void AppTranslator::retranslate()
|
|||||||
last->deleteLater();
|
last->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
// QStringList TranslationLoader::availableLanguages()
|
|
||||||
//{
|
|
||||||
// QStringList result{QLocale(builtin).nativeLanguageName()};
|
|
||||||
// auto checker = new QTranslator(QApplication::instance());
|
|
||||||
|
|
||||||
// for (const auto &dir : searchPaths()) {
|
|
||||||
// for (const auto &file :
|
|
||||||
// QDir(dir).entryInfoList({appTranslation + '*'}, QDir::Files)) {
|
|
||||||
// if (checker->load(file.absoluteFilePath())) {
|
|
||||||
// const auto name = file.baseName();
|
|
||||||
// const auto suffixIndex = name.indexOf(QLatin1Char('_'));
|
|
||||||
// if (suffixIndex < 0) {
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// const auto suffix = name.mid(suffixIndex + 1);
|
|
||||||
// const auto locale = QLocale(suffix);
|
|
||||||
// const auto language = locale.nativeLanguageName();
|
|
||||||
// if (!result.contains(language)) {
|
|
||||||
// result.append(language);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return result;
|
|
||||||
//}
|
|
||||||
|
|
||||||
// QString TranslationLoader::language()
|
|
||||||
//{
|
|
||||||
// return toLanguage(translation());
|
|
||||||
//}
|
|
||||||
|
|
||||||
// void TranslationLoader::setLanguage(const QString &language)
|
|
||||||
//{
|
|
||||||
// setTranslation(toTranslation(language));
|
|
||||||
//}
|
|
||||||
|
|
||||||
// QString TranslationLoader::translation()
|
|
||||||
//{
|
|
||||||
// SettingsManager settings;
|
|
||||||
// auto name = settings.get(SettingsManager::Translation).toString();
|
|
||||||
// if (name.isEmpty()) {
|
|
||||||
// const QLocale locale;
|
|
||||||
// if (locale.language() == QLocale::Language::C) {
|
|
||||||
// name = QLocale(builtin).name();
|
|
||||||
// } else {
|
|
||||||
// name = locale.name();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return name;
|
|
||||||
//}
|
|
||||||
|
|
||||||
// void TranslationLoader::setTranslation(const QString &translation)
|
|
||||||
//{
|
|
||||||
// SettingsManager settings;
|
|
||||||
// settings.set(SettingsManager::Translation, translation);
|
|
||||||
//}
|
|
||||||
|
|
||||||
QStringList AppTranslator::searchPaths() const
|
QStringList AppTranslator::searchPaths() const
|
||||||
{
|
{
|
||||||
return QStringList{
|
return QStringList{
|
||||||
@ -111,21 +46,6 @@ QStringList AppTranslator::searchPaths() const
|
|||||||
#endif // ifdef Q_OS_LINUX
|
#endif // ifdef Q_OS_LINUX
|
||||||
{},
|
{},
|
||||||
QLatin1String("translations"),
|
QLatin1String("translations"),
|
||||||
|
QLatin1String(":/translations"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// QString TranslationLoader::toLanguage(const QString &translation)
|
|
||||||
//{
|
|
||||||
// return QLocale(translation).nativeLanguageName();
|
|
||||||
//}
|
|
||||||
|
|
||||||
// QString TranslationLoader::toTranslation(const QString &language)
|
|
||||||
//{
|
|
||||||
// for (auto i = 0; i < QLocale::Language::LastLanguage; ++i) {
|
|
||||||
// const auto locale = QLocale(QLocale::Language(i));
|
|
||||||
// if (locale.nativeLanguageName() == language) {
|
|
||||||
// return locale.name();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return QLocale().name();
|
|
||||||
//}
|
|
||||||
|
@ -9,17 +9,7 @@ public:
|
|||||||
|
|
||||||
void retranslate();
|
void retranslate();
|
||||||
|
|
||||||
// static QStringList availableLanguages();
|
|
||||||
// static QString language();
|
|
||||||
// static void setLanguage(const QString &language);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// static QString translation();
|
|
||||||
// static void setTranslation(const QString &translation);
|
|
||||||
QStringList searchPaths() const;
|
QStringList searchPaths() const;
|
||||||
|
|
||||||
// static QString toTranslation(const QString &language);
|
|
||||||
// static QString toLanguage(const QString &translation);
|
|
||||||
|
|
||||||
QStringList translationFiles_;
|
QStringList translationFiles_;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user