summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--po/de.po2
-rw-r--r--po/de_DE.po2
-rw-r--r--po/en.po15
-rw-r--r--pykolab/translate.py16
-rw-r--r--tests/unit/test-015-translate.py25
5 files changed, 58 insertions, 2 deletions
diff --git a/po/de.po b/po/de.po
index ff7abe2..b49222d 100644
--- a/po/de.po
+++ b/po/de.po
@@ -721,7 +721,7 @@ msgstr ""
#: ../pykolab/cli/cmd_set_mailbox_acl.py:54
#: ../pykolab/cli/cmd_set_mailbox_metadata.py:54
msgid "Folder name"
-msgstr ""
+msgstr "Ordnername"
#: ../pykolab/cli/cmd_delete_mailbox_acl.py:60
#: ../pykolab/cli/cmd_list_mailbox_acls.py:52
diff --git a/po/de_DE.po b/po/de_DE.po
index 03f16f2..e849ee9 100644
--- a/po/de_DE.po
+++ b/po/de_DE.po
@@ -686,7 +686,7 @@ msgstr ""
#: ../pykolab/cli/cmd_set_mailbox_acl.py:54
#: ../pykolab/cli/cmd_set_mailbox_metadata.py:65
msgid "Folder name"
-msgstr ""
+msgstr "Ordnername"
#: ../pykolab/cli/cmd_delete_mailbox_acl.py:60
#: ../pykolab/cli/cmd_list_mailbox_acls.py:54
diff --git a/po/en.po b/po/en.po
new file mode 100644
index 0000000..da6a905
--- /dev/null
+++ b/po/en.po
@@ -0,0 +1,15 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: Kolab Groupware Solution\n"
+"Report-Msgid-Bugs-To: https://isues.kolab.org/\n"
+"POT-Creation-Date: 2014-07-17 10:22+0100\n"
+"PO-Revision-Date: 2014-07-14 11:13+0000\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Language: en\n"
+"Plural-Forms: nplurals=2; plural=(n != 1)\n"
diff --git a/pykolab/translate.py b/pykolab/translate.py
index bee8fc2..85f4516 100644
--- a/pykolab/translate.py
+++ b/pykolab/translate.py
@@ -28,6 +28,8 @@ import os
N_ = lambda x: x
_ = lambda x: gettext.ldgettext(domain, x)
+#gettext.bindtextdomain(domain, '/usr/local/share/locale')
+
def getDefaultLangs():
languages = []
for envar in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'):
@@ -45,3 +47,17 @@ def getDefaultLangs():
if nelang not in nelangs:
nelangs.append(nelang)
return nelangs
+
+def setUserLanguage(lang):
+ langs = []
+ for l in gettext._expand_lang(lang):
+ if l not in langs:
+ langs.append(l)
+
+ try:
+ translation = gettext.translation(domain, languages=langs)
+ translation.install()
+ except:
+ return False
+
+ return True
diff --git a/tests/unit/test-015-translate.py b/tests/unit/test-015-translate.py
new file mode 100644
index 0000000..8ca9463
--- /dev/null
+++ b/tests/unit/test-015-translate.py
@@ -0,0 +1,25 @@
+import unittest
+import gettext
+from pykolab import translate
+
+class TestTranslate(unittest.TestCase):
+
+ def setUp(self):
+ translate.setUserLanguage('en')
+
+ def test_001_default_langs(self):
+ self.assertTrue(len(translate.getDefaultLangs()) > 0)
+
+ def test_002_translate(self):
+ from pykolab.translate import _
+ self.assertEqual(_("Folder name"), "Folder name")
+
+ def test_003_set_lang(self):
+ from pykolab.translate import _
+ self.assertFalse(translate.setUserLanguage('foo_bar'))
+ self.assertEqual(_("Folder name"), "Folder name")
+ self.assertTrue(translate.setUserLanguage('de_DE'))
+ self.assertEqual(_("Folder name"), "Ordnername")
+
+if __name__ == '__main__':
+ unittest.main()