From e28c32bbf42481c007e7f74c32bc5a74c89f713e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Thu, 19 Apr 2018 17:21:28 +0200 Subject: [PATCH] Implement dynamic translation loading mechanism --- libnymea-core/nymeaconfiguration.cpp | 2 +- libnymea-core/nymeacore.cpp | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/libnymea-core/nymeaconfiguration.cpp b/libnymea-core/nymeaconfiguration.cpp index ff971d81..8657b145 100644 --- a/libnymea-core/nymeaconfiguration.cpp +++ b/libnymea-core/nymeaconfiguration.cpp @@ -222,7 +222,7 @@ QLocale NymeaConfiguration::locale() const void NymeaConfiguration::setLocale(const QLocale &locale) { - qCDebug(dcApplication()) << "Configuration: set locale:" << locale.name() << locale.nativeCountryName() << locale.nativeLanguageName(); + qCDebug(dcApplication()) << "Configuration: Set system locale:" << locale.name() << locale.nativeCountryName() << locale.nativeLanguageName(); NymeaSettings settings(NymeaSettings::SettingsRoleGlobal); settings.beginGroup("nymead"); diff --git a/libnymea-core/nymeacore.cpp b/libnymea-core/nymeacore.cpp index 88220f7d..1f319592 100644 --- a/libnymea-core/nymeacore.cpp +++ b/libnymea-core/nymeacore.cpp @@ -106,6 +106,8 @@ #include "plugin/device.h" #include "cloudnotifications.h" +#include + namespace nymeaserver { NymeaCore* NymeaCore::s_instance = 0; @@ -437,8 +439,23 @@ ServerManager *NymeaCore::serverManager() const /*! Returns the list of available system languages. */ QStringList NymeaCore::getAvailableLanguages() { - // FIXME: load available translations - return QStringList() << "en_US" << "de_DE"; + qCDebug(dcApplication()) << "Loading translations from" << NymeaSettings::translationsPath(); + + QDir translationDirectory(NymeaSettings::translationsPath()); + translationDirectory.setNameFilters(QStringList() << "*.qm"); + QStringList translationFiles = translationDirectory.entryList(); + + QStringList availableLanguages; + foreach (QString translationFile, translationFiles) { + if (!translationFile.startsWith("nymead-")) + continue; + + QString language = translationFile.remove("nymead-").remove(".qm"); + QLocale languageLocale(language); + availableLanguages.append(languageLocale.name()); + } + + return availableLanguages; } /*! Returns a pointer to the \l{BluetoothServer} instance owned by NymeaCore. */