Skip to content

Commit

Permalink
Translations suppport to server side code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajalkane committed May 6, 2014
1 parent efc2743 commit ddf9ab3
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
1 change: 1 addition & 0 deletions profilematic/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ QString adjustPath(const QString &path)
qDebug() << Q_FUNC_INFO << "returning default" << path;
return path;
}

void setupTranslations(QApplication *app, QTranslator *translator) {
QString locale = QLocale::system().name();
QString translationsDir = adjustPath("i18n");
Expand Down
4 changes: 2 additions & 2 deletions profilematicd/src/logic/rulesmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ RulesManager::_refresh(bool /*forceActivate*/) {

void
RulesManager::_notifyOfNewMatchingRule(const Rule &rule) {
// TODO: translations
PlatformUtil::instance()->publishNotification(rule.getRuleName() + " activated");
//: Used to show when rule is activated, ie. when rule's conditions match
PlatformUtil::instance()->publishNotification(tr("%1 activated").arg(rule.getRuleName()));
}

void
Expand Down
47 changes: 46 additions & 1 deletion profilematicd/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <QtCore/QCoreApplication>
#include <QDBusMetaType>
#include <QProcess>
#include <QTranslator>
#include <QFileInfo>

#include "model/rule.h"

Expand All @@ -40,6 +42,8 @@
#define CREDENTIAL_WARNING_CMDLINE "/opt/profilematic/bin/profilematic -credentialWarning"
#define MULTIRULE_WARNING_CMDLINE "/opt/profilematic/bin/profilematic -multiRuleWarning"

void setupTranslations(QCoreApplication *app, QTranslator *translator);

void noLoggingSink(QtMsgType, const char *) {
// NOP
}
Expand Down Expand Up @@ -72,11 +76,13 @@ int main(int argc, char *argv[])
// qInstallMsgHandler(noLoggingSink);
}

QTranslator translator;
setupTranslations(&a, &translator);

PlatformUtil::initialize();
ProfileClient profileClient;
Preferences preferences;
int rules_version = -1;
// TODO
RulesHolder rulesHolder(&profileClient);
Configuration::readRules(rulesHolder, &rules_version);
Configuration::readPreferences(preferences);
Expand Down Expand Up @@ -121,3 +127,42 @@ int main(int argc, char *argv[])

return ret;
}

QString adjustPath(const QString &path)
{
#ifdef Q_OS_UNIX
#ifdef Q_OS_MAC
if (!QDir::isAbsolutePath(path))
return QString::fromLatin1("%1/../Resources/%2")
.arg(QCoreApplication::applicationDirPath(), path);
#else
const QString pathInInstallDir =
QString::fromLatin1("%1/../%2").arg(QCoreApplication::applicationDirPath(), path);
qDebug() << Q_FUNC_INFO << "got candidate" << pathInInstallDir;
if (QFileInfo(pathInInstallDir).exists())
return pathInInstallDir;
#endif
#endif
qDebug() << Q_FUNC_INFO << "returning default" << path;
return path;
}

void setupTranslations(QCoreApplication *app, QTranslator *translator) {
QString locale = QLocale::system().name();
QString translationsDir = adjustPath("i18n");
qDebug() << "Locale:" << locale << " translationsDir:" << translationsDir;

// fall back to using English translation, if one specific to the current
// setting of the device is not available.
if (!(translator->load("tr_"+locale, translationsDir))) {
qDebug() << "Translation for locale " << locale << " not found, loading default english";
if (!translator->load("tr_en", translationsDir)) {
qWarning() << "Translation for default english not found either. Annoying.";
} else {
qDebug() << "Default english translation used for locale " << locale;
}
} else {
qDebug() << "Found translation used for locale " << locale;
}
app->installTranslator(translator);
}
2 changes: 1 addition & 1 deletion profilematicd/tests/logic/testconditionmanagercalendar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// rounding.
// Now has buffer of 2, since at least on Harmattan the timer seemed to have triggered
// between day intervals on 23:59:59. Will see if this corrects it.
// TODO: this depends on value in conditionmanagercalendar.cpp. Make it usable from test.
// IMPROVE: this depends on value in conditionmanagercalendar.cpp. Make it usable from test.
#define SECS_TO_BUFFER 2

class MockCalendarManager : public CalendarManager {
Expand Down

0 comments on commit ddf9ab3

Please sign in to comment.