summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2014-07-10 06:26:46 -0400
committerThomas Bruederli <bruederli@kolabsys.com>2014-07-10 06:26:46 -0400
commit5d97d7f2da3d97930941c081c8bbba7de687863f (patch)
tree2af18265a15d147abd7c5e30fb11139be91977ec
parent6b3df45c2cc13f5fcc3320404881cbff0a8f012e (diff)
downloadpykolab-5d97d7f2da3d97930941c081c8bbba7de687863f.tar.gz
Implement gettext language switch; remove en.po as this is not used
-rw-r--r--po/en.po15
-rw-r--r--pykolab/translate.py14
-rw-r--r--tests/unit/test-015-translate.py10
3 files changed, 11 insertions, 28 deletions
diff --git a/po/en.po b/po/en.po
deleted file mode 100644
index da6a905..0000000
--- a/po/en.po
+++ /dev/null
@@ -1,15 +0,0 @@
-# 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 85f4516..080cbc2 100644
--- a/pykolab/translate.py
+++ b/pykolab/translate.py
@@ -26,9 +26,10 @@ import gettext
import os
N_ = lambda x: x
-_ = lambda x: gettext.ldgettext(domain, x)
+_ = lambda x: current.lgettext(x)
-#gettext.bindtextdomain(domain, '/usr/local/share/locale')
+localedir = '/usr/local/share/locale'
+current = gettext.translation(domain, localedir, fallback=True)
def getDefaultLangs():
languages = []
@@ -49,15 +50,14 @@ def getDefaultLangs():
return nelangs
def setUserLanguage(lang):
+ global current
+
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()
+ current = gettext.translation(domain, localedir, languages=langs, fallback=True)
except:
- return False
-
- return True
+ pass
diff --git a/tests/unit/test-015-translate.py b/tests/unit/test-015-translate.py
index 8ca9463..6819b80 100644
--- a/tests/unit/test-015-translate.py
+++ b/tests/unit/test-015-translate.py
@@ -4,9 +4,6 @@ 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)
@@ -16,10 +13,11 @@ class TestTranslate(unittest.TestCase):
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")
+ translate.setUserLanguage('de_DE')
+ self.assertEqual(_("Folder name"), "Ordnername", "German Translation found")
+ translate.setUserLanguage('foo_bar')
+ self.assertEqual(_("Folder name"), "Folder name", "Unkonwn language falls back to NullTranslations")
if __name__ == '__main__':
unittest.main()