Page MenuHomePhorge

translit.py
No OneTemporary

Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None

translit.py

# -*- coding: utf-8 -*-
# Copyright 2010-2013 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, either version 3 of the License, 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 General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import pykolab
from pykolab.translate import _
log = pykolab.getLogger('pykolab.translit')
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):
if locale_translit_map.has_key(lang):
_translit_name = locale_translit_map[lang]
else:
_translit_name = lang
_output = ''
if not isinstance(_input, unicode):
for char in _input.decode('utf-8'):
if translit_map.has_key(_translit_name):
if translit_map[_translit_name].has_key(char):
_output += translit_map[_translit_name][char]
elif char in [repr(x) for x in translit_map[_translit_name].keys()]:
_output += translit_map[_translit_name][[char in [raw(x) for x in translit_map[_translit_name].keys()]][0]]
else:
_output += char
else:
_output += char
else:
for char in _input:
if translit_map.has_key(_translit_name):
if translit_map[_translit_name].has_key(char):
_output += translit_map[_translit_name][char]
elif char in [repr(x) for x in translit_map[_translit_name].keys()]:
_output += translit_map[_translit_name][[char in [raw(x) for x in translit_map[_translit_name].keys()]][0]]
else:
_output += char
else:
_output += char
return _output

File Metadata

Mime Type
text/x-script.python
Expires
Mon, Apr 6, 12:39 AM (6 d, 4 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
1c/df/703da0b89d3bab406010ecb9d9e5
Default Alt Text
translit.py (4 KB)

Event Timeline