summaryrefslogtreecommitdiffstats
path: root/pykolab
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-02-08 16:16:23 +0000
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-02-08 16:16:23 +0000
commit45078a3b0d84429ccaf8dc6ff5ae7a5eb6751078 (patch)
tree5bd46f71e183e9cb67ed4b6c040ac489b79ba462 /pykolab
parent012c5e29572aef7747f2a4ce54b09d4b1eb79703 (diff)
downloadpykolab-45078a3b0d84429ccaf8dc6ff5ae7a5eb6751078.tar.gz
Provide an initial locale -> translit lookup table set and a function to call
Diffstat (limited to 'pykolab')
-rw-r--r--pykolab/translit.py107
1 files changed, 107 insertions, 0 deletions
diff --git a/pykolab/translit.py b/pykolab/translit.py
new file mode 100644
index 0000000..ac4d2d7
--- /dev/null
+++ b/pykolab/translit.py
@@ -0,0 +1,107 @@
+# -*- coding: utf-8 -*-
+# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com)
+#
+# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 3 or, at your option, any later version
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+
+locale_translit_map = {
+ 'ru_RU': 'cyrillic'
+ }
+
+translit_map = {
+ 'cyrillic': {
+ u'А': 'A',
+ u'а': 'a',
+ u'Б': 'B',
+ u'б': 'b',
+ u'В': 'V',
+ u'в': 'v',
+ u'Г': 'G',
+ u'г': 'g',
+ u'Д': 'D',
+ u'д': 'd',
+ u'Е': 'E',
+ u'е': 'e',
+ u'Ё': 'Yo',
+ u'ё': 'e',
+ u'Ж': 'Zh',
+ u'ж': 'zh',
+ u'З': 'Z',
+ u'з': 'z',
+ u'И': 'I',
+ u'и': 'i',
+ u'Й': 'J',
+ u'й': 'j',
+ u'К': 'K',
+ u'к': 'k',
+ u'Л': 'L',
+ u'л': 'l',
+ u'М': 'M',
+ u'м': 'm',
+ u'Н': 'N',
+ u'н': 'n',
+ u'О': 'O',
+ u'о': 'o',
+ u'П': 'P',
+ u'п': 'p',
+ u'Р': 'R',
+ u'р': 'r',
+ u'С': 'S',
+ u'с': 's',
+ u'Т': 'T',
+ u'т': 't',
+ u'У': 'U',
+ u'у': 'u',
+ u'Ф': 'F',
+ u'ф': 'f',
+ u'Х': 'Kh',
+ u'х': 'kh',
+ u'Ц': 'Tc',
+ u'ц': 'tc',
+ u'Ч': 'Ch',
+ u'ч': 'ch',
+ u'Ш': 'Sh',
+ u'ш': 'sh',
+ u'Щ': 'Shch',
+ u'щ': 'shch',
+ u'Ъ': '',
+ u'ъ': '',
+ u'Ы': 'Y',
+ u'ы': 'y',
+ u'Ь': '',
+ u'ь': '',
+ u'Э': 'E',
+ u'э': 'e',
+ u'Ю': 'Yu',
+ u'ю': 'yu',
+ u'Я': 'Ya',
+ u'я': 'ya',
+ }
+ }
+
+def transliterate(_input, lang, _output_expected=None):
+ _translit_name = locale_translit_map[lang]
+
+ _output = ''
+
+ for char in _input:
+ if translit_map[_translit_name].has_key(char):
+ _output += translit_map[_translit_name][char]
+ else:
+ _output += char
+
+ return _output
+