begin with translation process

pull/135/head
Simon Stürz 2016-07-21 21:48:09 +02:00 committed by Michael Zanetti
parent 6805f894d2
commit 3db2fe81d6
18 changed files with 154 additions and 8 deletions

View File

@ -194,8 +194,9 @@
/*! Constructs the DeviceManager with the given \a parent. There should only be one DeviceManager in the system created by \l{guhserver::GuhCore}.
* Use \c guhserver::GuhCore::instance()->deviceManager() instead to access the DeviceManager. */
DeviceManager::DeviceManager(QObject *parent) :
DeviceManager::DeviceManager(const QLocale &locale, QObject *parent) :
QObject(parent),
m_locale(locale),
m_radio433(0)
{
qRegisterMetaType<DeviceClassId>();
@ -986,6 +987,9 @@ void DeviceManager::loadPlugins()
continue;
}
pluginIface->setLocale(m_locale);
qApp->installTranslator(pluginIface->translator());
if (verifyPluginMetadata(loader.metaData().value("MetaData").toObject())) {
pluginIface->initPlugin(loader.metaData().value("MetaData").toObject(), this);
qCDebug(dcDeviceManager) << "**** Loaded plugin" << pluginIface->pluginName();

View File

@ -43,6 +43,7 @@
#include <QObject>
#include <QTimer>
#include <QLocale>
#include <QPluginLoader>
class Device;
@ -102,7 +103,7 @@ public:
DeviceSetupStatusAsync
};
explicit DeviceManager(QObject *parent = 0);
explicit DeviceManager(const QLocale &locale, QObject *parent = 0);
~DeviceManager();
static QStringList pluginSearchDirs();
@ -189,6 +190,7 @@ private:
void postSetupDevice(Device *device);
private:
QLocale m_locale;
QHash<VendorId, Vendor> m_supportedVendors;
QHash<VendorId, QList<DeviceClassId> > m_vendorDeviceMap;
QHash<DeviceClassId, DeviceClass> m_supportedDevices;

View File

@ -186,6 +186,11 @@ QString GuhSettings::settingsPath()
return path;
}
QString GuhSettings::translationsPath()
{
return QString("/usr/share/guh/translations");
}
/*! Returns the path where the log file (console log) will be stored. */
QString GuhSettings::consoleLogPath()
{

View File

@ -48,6 +48,7 @@ public:
static bool isRoot();
static QString logPath();
static QString settingsPath();
static QString translationsPath();
static QString consoleLogPath();
// forwarded QSettings methods

View File

@ -148,7 +148,8 @@
/*! DevicePlugin constructor. DevicePlugins will be instantiated by the DeviceManager, its \a parent. */
DevicePlugin::DevicePlugin(QObject *parent):
QObject(parent)
QObject(parent),
m_translator(new QTranslator(this))
{
}
@ -440,6 +441,16 @@ QList<DeviceClass> DevicePlugin::supportedDevices() const
return deviceClasses;
}
QTranslator *DevicePlugin::translator()
{
return m_translator;
}
void DevicePlugin::setLocale(const QLocale &locale)
{
m_translator->load(locale, pluginName(), "_", GuhSettings::translationsPath(), ".qm");
}
/*! Override this if your plugin supports Device with DeviceClass::CreationMethodAuto.
This will be called at startup, after the configured devices have been loaded.
This is the earliest time you should start emitting autoDevicesAppeared(). If you

View File

@ -41,6 +41,7 @@
#include <QMetaEnum>
#include <QJsonObject>
#include <QMetaObject>
#include <QTranslator>
#include <QPair>
class DeviceManager;
@ -60,6 +61,9 @@ public:
QList<Vendor> supportedVendors() const;
QList<DeviceClass> supportedDevices() const;
QTranslator *translator();
void setLocale(const QLocale &locale);
virtual DeviceManager::HardwareResources requiredHardware() const = 0;
virtual void startMonitoringAutoDevices();
@ -137,6 +141,7 @@ private:
QPair<bool, DeviceClass::BasicTag> loadAndVerifyBasicTag(const QString &basicTag) const;
QPair<bool, DeviceClass::DeviceIcon> loadAndVerifyDeviceIcon(const QString &deviceIcon) const;
QTranslator *m_translator;
DeviceManager *m_deviceManager;
QList<ParamType> m_configurationDescription;

View File

@ -5,7 +5,12 @@ CONFIG += plugin
QT += network
INCLUDEPATH += ../../../libguh
# Check Bluetooth LE support
contains(DEFINES, BLUETOOTH_LE) {
QT += bluetooth
}
INCLUDEPATH += $$top_srcdir/libguh
LIBS += -L../../../libguh -lguh
infofile.output = plugininfo.h

View File

@ -381,6 +381,12 @@ ServerManager *GuhCore::serverManager() const
return m_serverManager;
}
QStringList GuhCore::getAvailableLanguages()
{
// TODO: parse available translation files
return QStringList() << "en_US" << "de_DE";
}
BluetoothServer *GuhCore::bluetoothServer() const
{
return m_bluetoothServer;
@ -416,7 +422,7 @@ GuhCore::GuhCore(QObject *parent) :
m_cloudManager = new CloudManager(m_configuration->cloudEnabled(), m_configuration->cloudAuthenticationServer(), m_configuration->cloudProxyServer(), this);
qCDebug(dcApplication) << "Creating Device Manager";
m_deviceManager = new DeviceManager(this);
m_deviceManager = new DeviceManager(m_configuration->locale(), this);
qCDebug(dcApplication) << "Creating Rule Engine";
m_ruleEngine = new RuleEngine(this);

View File

@ -87,6 +87,7 @@ public:
ServerManager *serverManager() const;
BluetoothServer *bluetoothServer() const;
static QStringList getAvailableLanguages();
#ifdef TESTING_ENABLED
MockTcpServer *tcpServer() const;

View File

@ -33,6 +33,12 @@ ConfigurationHandler::ConfigurationHandler(QObject *parent):
returns.insert("timeZones", QVariantList() << JsonTypes::basicTypeToString(JsonTypes::String));
setReturns("GetTimeZones", returns);
params.clear(); returns.clear();
setDescription("GetAvailableLanguages", "Returns a list of locale codes available for the server. i.e. en_US, de_AT");
setParams("GetAvailableLanguages", params);
returns.insert("languages", QVariantList() << JsonTypes::basicTypeToString(JsonTypes::String));
setReturns("GetAvailableLanguages", returns);
params.clear(); returns.clear();
setDescription("GetConfigurations", "Get all configuration parameters of the server.");
setParams("GetConfigurations", params);
@ -41,6 +47,7 @@ ConfigurationHandler::ConfigurationHandler(QObject *parent):
basicConfiguration.insert("serverUuid", JsonTypes::basicTypeToString(JsonTypes::Uuid));
basicConfiguration.insert("serverTime", JsonTypes::basicTypeToString(JsonTypes::Uint));
basicConfiguration.insert("timeZone", JsonTypes::basicTypeToString(JsonTypes::String));
basicConfiguration.insert("language", JsonTypes::basicTypeToString(JsonTypes::String));
returns.insert("basicConfiguration", basicConfiguration);
QVariantMap tcpServerConfiguration;
tcpServerConfiguration.insert("host", JsonTypes::basicTypeToString(JsonTypes::String));
@ -73,6 +80,13 @@ ConfigurationHandler::ConfigurationHandler(QObject *parent):
returns.insert("configurationError", JsonTypes::configurationErrorRef());
setReturns("SetTimeZone", returns);
params.clear(); returns.clear();
setDescription("SetLanguage", "Sets the server language to the given language. See also: \"GetAvailableLanguages\"");
params.insert("language", JsonTypes::basicTypeToString(JsonTypes::String));
setParams("SetLanguage", params);
returns.insert("configurationError", JsonTypes::configurationErrorRef());
setReturns("SetLanguage", returns);
params.clear(); returns.clear();
setDescription("SetTcpServerConfiguration", "Configure the TCP interface of the server. Note: if you are using the TCP server for this call you will loose the connection.");
params.insert("host", JsonTypes::basicTypeToString(JsonTypes::String));
@ -124,8 +138,9 @@ ConfigurationHandler::ConfigurationHandler(QObject *parent):
params.insert("port", JsonTypes::basicTypeToString(JsonTypes::Uint));
setParams("WebSocketServerConfigurationChanged", params);
connect(GuhCore::instance()->configuration(), &GuhConfiguration::timeZoneChanged, this, &ConfigurationHandler::onBasicConfigurationChanged);
connect(GuhCore::instance()->configuration(), &GuhConfiguration::serverNameChanged, this, &ConfigurationHandler::onBasicConfigurationChanged);
connect(GuhCore::instance()->configuration(), &GuhConfiguration::timeZoneChanged, this, &ConfigurationHandler::onBasicConfigurationChanged);
connect(GuhCore::instance()->configuration(), &GuhConfiguration::localeChanged, this, &ConfigurationHandler::onBasicConfigurationChanged);
connect(GuhCore::instance()->configuration(), &GuhConfiguration::tcpServerConfigurationChanged, this, &ConfigurationHandler::onTcpServerConfigurationChanged);
connect(GuhCore::instance()->configuration(), &GuhConfiguration::webServerConfigurationChanged, this, &ConfigurationHandler::onWebServerConfigurationChanged);
connect(GuhCore::instance()->configuration(), &GuhConfiguration::webSocketServerConfigurationChanged, this, &ConfigurationHandler::onWebSocketServerConfigurationChanged);
@ -163,6 +178,18 @@ JsonReply *ConfigurationHandler::GetTimeZones(const QVariantMap &params) const
return createReply(returns);
}
JsonReply *ConfigurationHandler::GetAvailableLanguages(const QVariantMap &params) const
{
Q_UNUSED(params)
QVariantList languages;
foreach (const QString &language, GuhCore::getAvailableLanguages()) {
languages.append(language);
}
QVariantMap returns;
returns.insert("languages", languages);
return createReply(returns);
}
JsonReply *ConfigurationHandler::SetServerName(const QVariantMap &params) const
{
QString serverName = params.value("serverName").toString();
@ -182,6 +209,16 @@ JsonReply *ConfigurationHandler::SetTimeZone(const QVariantMap &params) const
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorNoError));
}
JsonReply *ConfigurationHandler::SetLanguage(const QVariantMap &params) const
{
qCDebug(dcJsonRpc()) << "Setting language to" << params.value("language").toString();
QLocale locale(params.value("language").toString());
GuhCore::instance()->configuration()->setLocale(locale);
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorNoError));
}
JsonReply *ConfigurationHandler::SetTcpServerConfiguration(const QVariantMap &params) const
{
QHostAddress host = QHostAddress(params.value("host").toString());

View File

@ -37,8 +37,10 @@ public:
Q_INVOKABLE JsonReply *GetConfigurations(const QVariantMap &params) const;
Q_INVOKABLE JsonReply *GetTimeZones(const QVariantMap &params) const;
Q_INVOKABLE JsonReply *GetAvailableLanguages(const QVariantMap &params) const;
Q_INVOKABLE JsonReply *SetServerName(const QVariantMap &params) const;
Q_INVOKABLE JsonReply *SetTimeZone(const QVariantMap &params) const;
Q_INVOKABLE JsonReply *SetLanguage(const QVariantMap &params) const;
Q_INVOKABLE JsonReply *SetTcpServerConfiguration(const QVariantMap &params) const;
Q_INVOKABLE JsonReply *SetWebServerConfiguration(const QVariantMap &params) const;
Q_INVOKABLE JsonReply *SetWebSocketServerConfiguration(const QVariantMap &params) const;

View File

@ -270,8 +270,11 @@ void JsonRPCServer::clientConnected(const QUuid &clientId)
QVariantMap handshake;
handshake.insert("id", 0);
handshake.insert("server", "guh JSONRPC interface");
handshake.insert("server", "guhIO");
handshake.insert("name", GuhCore::instance()->configuration()->serverName());
handshake.insert("version", GUH_VERSION_STRING);
handshake.insert("uuid", GuhCore::instance()->configuration()->serverUuid().toString());
handshake.insert("language", GuhCore::instance()->configuration()->locale().name());
handshake.insert("protocol version", JSON_PROTOCOL_VERSION);
interface->sendData(clientId, handshake);
}

View File

@ -1003,6 +1003,7 @@ QVariantMap JsonTypes::packBasicConfiguration()
basicConfiguration.insert("serverUuid", GuhCore::instance()->configuration()->serverUuid());
basicConfiguration.insert("serverTime", GuhCore::instance()->timeManager()->currentDateTime().toTime_t());
basicConfiguration.insert("timeZone", QString::fromUtf8(GuhCore::instance()->timeManager()->timeZone()));
basicConfiguration.insert("language", GuhCore::instance()->configuration()->locale().name());
return basicConfiguration;
}

View File

@ -145,7 +145,7 @@ int main(int argc, char *argv[])
QCommandLineOption foregroundOption(QStringList() << "n" << "no-daemon", QCoreApplication::translate("main", "Run guhd in the foreground, not as daemon."));
parser.addOption(foregroundOption);
QString debugDescription = QString("Debug categories to enable. Prefix with \"No\" to disable. Warnings from all categories will be printed unless explicitly muted with \"NoWarnings\". \n\nCategories are:");
QString debugDescription = QCoreApplication::translate("main", "Debug categories to enable. Prefix with \"No\" to disable. Warnings from all categories will be printed unless explicitly muted with \"NoWarnings\". \n\nCategories are:");
// create sorted loggingFiler list
QStringList sortedFilterList = QStringList(s_loggingFilters.keys());

View File

@ -12,6 +12,13 @@ QT += sql xml websockets bluetooth
LIBS += -L$$top_builddir/libguh/ -lguh
# Translations
TRANSLATIONS *= $$top_srcdir/translations/guhd_en_US.ts \
$$top_srcdir/translations/guhd_de_DE.ts
include(../translations.pri)
# Server files
include(server.pri)
include(qtservice/qtservice.pri)

17
translations.pri Normal file
View File

@ -0,0 +1,17 @@
include(guh.pri)
# Create translation files
lrelease.input = TRANSLATIONS
lrelease.output = $$top_srcdir/${QMAKE_FILE_BASE}.qm
lrelease.commands = $$[QT_INSTALL_BINS]/lupdate ${QMAKE_FILE_IN} -ts $$TRANSLATIONS; $$[QT_INSTALL_BINS]/lrelease ${QMAKE_FILE_IN} -qm ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.qm
lrelease.CONFIG += no_link
QMAKE_EXTRA_COMPILERS += lrelease
PRE_TARGETDEPS += compiler_lrelease_make_all
message("Translations:" $$TRANSLATIONS )
translations.path = /usr/share/guh/translations
translations.files = $$[QT_SOURCE_TREE]/translations/*.qm
INSTALLS += translations

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="de_DE">
<context>
<name>main</name>
<message>
<location filename="../server/main.cpp" line="145"/>
<source>Run guhd in the foreground, not as daemon.</source>
<translation>Starte guhd im Vordergrund, nicht als service.</translation>
</message>
<message>
<location filename="../server/main.cpp" line="148"/>
<source>Debug categories to enable. Prefix with &quot;No&quot; to disable. Warnings from all categories will be printed unless explicitly muted with &quot;NoWarnings&quot;.
Categories are:</source>
<translation>Zu aktivierende Debug-Kategorien. Kategorien mit dem Präfix &quot;No&quot; werden deaktiviert. Warnungen werden von allen Kategorien ausgegeben außer sie wurden explizit mit dem Prefix &quot;NoWarnings&quot; deaktiviert.
Kategorien sind:</translation>
</message>
</context>
</TS>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="en_US">
<context>
<name>main</name>
<message>
<location filename="../server/main.cpp" line="145"/>
<source>Run guhd in the foreground, not as daemon.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../server/main.cpp" line="148"/>
<source>Debug categories to enable. Prefix with &quot;No&quot; to disable. Warnings from all categories will be printed unless explicitly muted with &quot;NoWarnings&quot;.
Categories are:</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>