Skip to content

Instantly share code, notes, and snippets.

@roktas
Created September 10, 2010 20:43
Show Gist options
  • Save roktas/574336 to your computer and use it in GitHub Desktop.
Save roktas/574336 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
#-*-coding:utf-8-*-
# Code stolen and modified from Emre Sevinç:
# http://github.com/emres/turkish-deasciifier
def set_char_at(string, pos, c):
return string[0:pos] + c + string[pos+1:]
def turkish_accent(c):
return {
u'ç': u'c',
u'Ç': u'C',
u'ğ': u'g',
u'Ğ': u'G',
u'ö': u'o',
u'Ö': u'O',
u'ü': u'u',
u'Ü': u'U',
u'ı': u'i',
u'İ': u'I',
u'ş': u's',
u'Ş': u'S',
}.get(c, c)
def turkish_asciify(string):
u"""Return an ascii string from a unicode Turkish string.
>>> turkish_asciify(u'abcığüşöçiIİĞÜŞÖÇ')
'abcigusociIIGUSOC'
"""
for i in range(len(string)):
string = set_char_at(string, i, turkish_accent(string[i]))
return str(string)
if __name__ == "__main__":
import doctest
doctest.testmod()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment