D-Bus server: localize auto sync notifications
The notification texts were already localized, but using localization was not turned on in the D-Bus server. The code which was meant to turn it on was incomplete. The setlocale() is required and was only done indirectly in syncevolution.org binaries if the KDE platform module was installed. Now it is done in main() as part of the process setup. Removed the incomplete setup code from the notify backend completely (instead of fixing it) because a plugin should not modify the process state like that. As part of adding a test for this feature, a new environment was added: the SYNCEVOLUTION_LOCALE_DIR environment variable can be set to the locale directory which contains the different translations. The English default text was already tested. The German translation gets activated via env variables in the same test and checks that localization works. Now that translation is working, better ensure that English is selected in those tests which expect English notifications.
This commit is contained in:
parent
f2583ff174
commit
5d99d86269
|
@ -1100,6 +1100,10 @@ SYNCEVOLUTION_LIBEXEC_DIR
|
|||
Overrides the path where additional helper executables are found, normally
|
||||
`/usr/libexec`.
|
||||
|
||||
SYNCEVOLUTION_LOCALE_DIR
|
||||
Overrides the path to directories with the different translations,
|
||||
normally `/usr/share/locale`.
|
||||
|
||||
SYNCEVOLUTION_TEMPLATE_DIR
|
||||
Overrides the default path to template files, normally
|
||||
`/usr/share/syncevolution/templates`.
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <locale.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "server.h"
|
||||
#include "restart.h"
|
||||
|
@ -70,6 +72,13 @@ int main(int argc, char **argv, char **envp)
|
|||
boost::shared_ptr<Restart> restart;
|
||||
restart.reset(new Restart(argv, envp));
|
||||
|
||||
// Internationalization for auto sync messages.
|
||||
setlocale(LC_ALL, "");
|
||||
bindtextdomain(GETTEXT_PACKAGE,
|
||||
getEnv("SYNCEVOLUTION_LOCALE_DIR", SYNCEVOLUTION_LOCALEDIR));
|
||||
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
|
||||
textdomain(GETTEXT_PACKAGE);
|
||||
|
||||
int duration = 600;
|
||||
int opt = 1;
|
||||
while(opt < argc) {
|
||||
|
|
|
@ -96,10 +96,6 @@ void NotificationBackendLibnotify::notifyAction(
|
|||
|
||||
bool NotificationBackendLibnotify::init()
|
||||
{
|
||||
bindtextdomain (GETTEXT_PACKAGE, SYNCEVOLUTION_LOCALEDIR);
|
||||
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
||||
textdomain (GETTEXT_PACKAGE);
|
||||
|
||||
#ifdef NOTIFY_COMPATIBILITY
|
||||
void *dlhandle = NULL;
|
||||
int i;
|
||||
|
|
|
@ -638,6 +638,16 @@ class SyncEvolutionTest(Action):
|
|||
"SYNCEVOLUTION_BACKEND_DIR=%s " \
|
||||
% ( datadir, templatedir, confdir, backenddir )
|
||||
|
||||
# Translations have no fallback, they must be installed. Leave unset
|
||||
# if not found.
|
||||
localedir = os.path.join(self.build.installdir, "usr/share/locale")
|
||||
print localedir
|
||||
if os.access(localedir, os.F_OK):
|
||||
installenv = installenv + \
|
||||
("SYNCEVOLUTION_LOCALE_DIR=%s " % localedir)
|
||||
else:
|
||||
print 'locale dir not found'
|
||||
|
||||
cmd = "%s %s %s %s %s ./syncevolution" % (self.testenv, installenv, self.runner, context.setupcmd, self.name)
|
||||
context.runCommand(cmd)
|
||||
|
||||
|
@ -647,7 +657,7 @@ class SyncEvolutionTest(Action):
|
|||
"CLIENT_TEST_SOURCES=%(sources)s " \
|
||||
"SYNC_EVOLUTION_EVO_CALENDAR_DELAY=1 " \
|
||||
"CLIENT_TEST_ALARM=%(alarm)d " \
|
||||
"%(env)s %(installenv)s" \
|
||||
"%(env)s %(installenv)s " \
|
||||
"CLIENT_TEST_LOG=%(log)s " \
|
||||
"CLIENT_TEST_EVOLUTION_PREFIX=%(evoprefix)s " \
|
||||
"%(runner)s " \
|
||||
|
|
|
@ -2679,18 +2679,35 @@ class TestSessionAPIsDummy(DBusUtil, unittest.TestCase):
|
|||
self.runTestDBusCheck = checkDBusLog
|
||||
|
||||
@timeout(60)
|
||||
@property("ENV", "LC_ALL=en_US.UTF-8 LANGUAGE=en_US")
|
||||
def testAutoSyncNetworkFailure(self):
|
||||
"""TestSessionAPIsDummy.testAutoSyncNetworkFailure - test that auto-sync is triggered, fails due to (temporary?!) network error here"""
|
||||
self.doAutoSyncNetworkFailure()
|
||||
|
||||
@timeout(60)
|
||||
@property("ENV", "DBUS_TEST_CONNMAN=session DBUS_TEST_NETWORK_MANAGER=session")
|
||||
@property("ENV", "DBUS_TEST_CONNMAN=session DBUS_TEST_NETWORK_MANAGER=session "
|
||||
"LC_ALL=en_US.UTF-8 LANGUAGE=en_US")
|
||||
def testAutoSyncNoNetworkManager(self):
|
||||
"""TestSessionAPIsDummy.testAutoSyncNoNetworkManager - test that auto-sync is triggered despite having neither NetworkManager nor Connman, fails due to (temporary?!) network error here"""
|
||||
self.doAutoSyncNetworkFailure()
|
||||
|
||||
@timeout(60)
|
||||
def doAutoSyncLocalConfigError(self, notifyLevel):
|
||||
def doAutoSyncLocalConfigError(self, notifyLevel,
|
||||
notification=
|
||||
' string "SyncEvolution"\n'
|
||||
' uint32 0\n'
|
||||
' string ""\n'
|
||||
' string "Sync problem."\n'
|
||||
' string "Sorry, there\'s a problem with your sync that you need to attend to."\n'
|
||||
' array [\n'
|
||||
' string "view"\n'
|
||||
' string "View"\n'
|
||||
' string "default"\n'
|
||||
' string "Dismiss"\n'
|
||||
' ]\n'
|
||||
' array [\n'
|
||||
' ]\n'
|
||||
' int32 -1\n'):
|
||||
self.setupConfig()
|
||||
# enable auto-sync
|
||||
config = copy.deepcopy(self.config)
|
||||
|
@ -2743,21 +2760,7 @@ class TestSessionAPIsDummy(DBusUtil, unittest.TestCase):
|
|||
def checkDBusLog(self, content):
|
||||
notifications = GrepNotifications(content)
|
||||
self.assertEqual(notifications,
|
||||
notifyLevel >= 1 and
|
||||
[' string "SyncEvolution"\n'
|
||||
' uint32 0\n'
|
||||
' string ""\n'
|
||||
' string "Sync problem."\n'
|
||||
' string "Sorry, there\'s a problem with your sync that you need to attend to."\n'
|
||||
' array [\n'
|
||||
' string "view"\n'
|
||||
' string "View"\n'
|
||||
' string "default"\n'
|
||||
' string "Dismiss"\n'
|
||||
' ]\n'
|
||||
' array [\n'
|
||||
' ]\n'
|
||||
' int32 -1\n']
|
||||
notifyLevel >= 1 and [notification]
|
||||
or [])
|
||||
|
||||
# check that no other session is started at the time of
|
||||
|
@ -2791,16 +2794,39 @@ class TestSessionAPIsDummy(DBusUtil, unittest.TestCase):
|
|||
self.runTestDBusCheck = checkDBusLog
|
||||
|
||||
@timeout(60)
|
||||
@property("ENV", "LC_ALL=en_US.UTF-8 LANGUAGE=en_US")
|
||||
def testAutoSyncLocalConfigError(self):
|
||||
"""TestSessionAPIsDummy.testAutoSyncLocalConfigError - test that auto-sync is triggered for local sync, fails due to permanent config error here"""
|
||||
self.doAutoSyncLocalConfigError(3)
|
||||
|
||||
@timeout(60)
|
||||
@property("ENV", "LC_ALL=de_DE.UTF-8 LANGUAGE=de_DE:de")
|
||||
def testAutoSyncLocalConfigErrorGerman(self):
|
||||
"""TestSessionAPIsDummy.testAutoSyncLocalConfigErrorGerman - test that auto-sync is triggered for local sync, fails due to permanent config error here"""
|
||||
self.doAutoSyncLocalConfigError(3,
|
||||
' string "SyncEvolution"\n'
|
||||
' uint32 0\n'
|
||||
' string ""\n'
|
||||
' string "Sync-Problem"\n'
|
||||
' string "Ein Problem mit der Synchronisation bedarf deiner Aufmerksamkeit."\n'
|
||||
' array [\n'
|
||||
' string "view"\n'
|
||||
' string "Anzeigen"\n'
|
||||
' string "default"\n'
|
||||
' string "Ignorieren"\n'
|
||||
' ]\n'
|
||||
' array [\n'
|
||||
' ]\n'
|
||||
' int32 -1\n')
|
||||
|
||||
@timeout(60)
|
||||
@property("ENV", "LC_ALL=en_US.UTF-8 LANGUAGE=en_US")
|
||||
def testAutoSyncLocalConfigErrorEssential(self):
|
||||
"""TestSessionAPIsDummy.testAutoSyncLocalConfigErrorEssential - test that auto-sync is triggered for local sync, fails due to permanent config error here, with only the essential error notification"""
|
||||
self.doAutoSyncLocalConfigError(1)
|
||||
|
||||
@timeout(60)
|
||||
@property("ENV", "LC_ALL=en_US.UTF-8 LANGUAGE=en_US")
|
||||
def testAutoSyncLocalConfigErrorQuiet(self):
|
||||
"""TestSessionAPIsDummy.testAutoSyncLocalConfigErrorQuiet - test that auto-sync is triggered for local sync, fails due to permanent config error here, with no notification"""
|
||||
self.doAutoSyncLocalConfigError(0)
|
||||
|
@ -2922,16 +2948,19 @@ class TestSessionAPIsDummy(DBusUtil, unittest.TestCase):
|
|||
self.runTestDBusCheck = checkDBusLog
|
||||
|
||||
@timeout(120)
|
||||
@property("ENV", "LC_ALL=en_US.UTF-8 LANGUAGE=en_US")
|
||||
def testAutoSyncLocalSuccess(self):
|
||||
"""TestSessionAPIsDummy.testAutoSyncLocalSuccess - test that auto-sync is done successfully for local sync between file backends, with notifications"""
|
||||
self.doAutoSyncLocalSuccess(3)
|
||||
|
||||
@timeout(120)
|
||||
@property("ENV", "LC_ALL=en_US.UTF-8 LANGUAGE=en_US")
|
||||
def testAutoSyncLocalSuccessQuiet(self):
|
||||
"""TestSessionAPIsDummy.testAutoSyncLocalSuccessQuiet - test that auto-sync is done successfully for local sync between file backends, without notifications"""
|
||||
self.doAutoSyncLocalSuccess(1)
|
||||
|
||||
@timeout(240)
|
||||
@property("ENV", "LC_ALL=en_US.UTF-8 LANGUAGE=en_US")
|
||||
def testAutoSyncLocalMultiple(self):
|
||||
"""TestSessionAPIsDummy.testAutoSyncLocalMultiple - test that auto-sync is done successfully for local sync between file backends, several times"""
|
||||
self.doAutoSyncLocalSuccess(1, repeat=True)
|
||||
|
|
Loading…
Reference in New Issue