Skip to content

Instantly share code, notes, and snippets.

@theasder
Created January 27, 2014 09:07
Show Gist options
  • Save theasder/8645350 to your computer and use it in GitHub Desktop.
Save theasder/8645350 to your computer and use it in GitHub Desktop.
Translit
# -*- coding: utf-8 -*-
def translit(s):
symbols = (u"абвгдеёзийклмнопрстуфхъыьэюАБВГДЕЁЗИЙКЛМНОПРСТУФХЪЫЬЭЬЬЮ",
u"abvgdeezijklmnoprstufh'y'euABVGDEEZIJKLMNOPRSTUFH'Y'EU")
tr = {ord(a):ord(b) for a, b in zip(*symbols)}
vac = {u'я': 'ya', u'ж': 'zh', u'ц': 'ts', u'ч': 'ch', u'ш': 'sh', u'щ': 'sch', u'Я': 'Ya', u'Ч': 'Ch', u'Ш': 'Sh', u'Щ': 'Sch', u'Ж': 'Zh', u'Ц': 'Ts'}
s = s.translate(tr)
s = ''.join([vac.get(c, c) for c in s])
return s
s = u"Лорем ипсум, напиши translit'ом"
a = translit(s)
print a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment