Implement dynamic translation loading mechanism
This commit is contained in:
parent
4e3b0ddb05
commit
e28c32bbf4
@ -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");
|
||||
|
||||
@ -106,6 +106,8 @@
|
||||
#include "plugin/device.h"
|
||||
#include "cloudnotifications.h"
|
||||
|
||||
#include <QDir>
|
||||
|
||||
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. */
|
||||
|
||||
Reference in New Issue
Block a user