summaryrefslogtreecommitdiff
path: root/pykolab/utils.py
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-02-08 16:16:56 (GMT)
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-02-08 16:16:56 (GMT)
commit6c82952f1f737e619d7ef95c0308a83336fa1ce1 (patch)
treef8d8f592fdd56518942c946a4a200f34ef46dea1 /pykolab/utils.py
parent45078a3b0d84429ccaf8dc6ff5ae7a5eb6751078 (diff)
downloadpykolab-6c82952f1f737e619d7ef95c0308a83336fa1ce1.tar.gz
Attempt to use iconv, but if it fails, fall back to using our own translit function (#1536)
Diffstat (limited to 'pykolab/utils.py')
-rw-r--r--pykolab/utils.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/pykolab/utils.py b/pykolab/utils.py
index 7f56c29..c10bbb2 100644
--- a/pykolab/utils.py
+++ b/pykolab/utils.py
@@ -415,10 +415,18 @@ def translate(mystring, locale_name='en_US'):
log.debug(_("Executing '%s | %s'") % (r"%s" % (mystring), ' '.join(command)), level=8)
process = subprocess.Popen(command, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE, env={'LANG': locale.normalize(locale_name)})
- print >> process.stdin, r"%s" % mystring
+ try:
+ print >> process.stdin, r"%s" % mystring
+ except UnicodeEncodeError, errmsg:
+ pass
result = process.communicate()[0].strip()
+ if '?' in result or (result == '' and not mystring == ''):
+ log.warning(_("Could not translate %s using locale %s") % (mystring, locale_name))
+ from pykolab import translit
+ result = translit.transliterate(mystring, locale_name)
+
return result
def true_or_false(val):