Skip to content

Instantly share code, notes, and snippets.

@dorukcan dorukcan/make_turkish.py
Last active Mar 12, 2019

Embed
What would you like to do?
def make_turkish(text, encode=False):
"""
Transforms a broken text to nice unicode equivalent.
:param text: Text to modify
:param encode: Boolean value indicates that whether encode the text to utf-8 or not
:return: Modified text
"""
if not text:
return None
if encode is True:
text = text.encode('latin1').decode('utf-8', 'backslashreplace')
tr_map = {
'\\xa0': ' ',
'\xa0': ' ',
'\t': ' ',
" ": "",
" ": "",
"¡": "¡",
"¡": "¡",
"¢": "¢",
"¢": "¢",
"£": "£",
"£": "£",
"¤": "¤",
"¤": "¤",
"¥": "¥",
"¥": "¥",
"¦": "¦",
"¦": "¦",
"§": "§",
"§": "§",
"¨": "¨",
"¨": "¨",
"©": "©",
"ª": "ª",
"ª": "ª",
"«": "«",
"«": "«",
"¬": "¬",
"¬": "¬",
"­": "­",
"­": "­",
"¯": "¯",
"¯": "¯",
"°": "°",
"°": "°",
"±": "±",
"±": "±",
"²": "²",
"²": "²",
"³": "³",
"³": "³",
"´": "´",
"´": "´",
'•': '•',
'“': '“',
'”': '”',
'‘': '‘',
'’': '’',
'ݾ': 'İ',
'Ý': 'İ',
'Ä°': 'İ',
'Ý': 'İ',
'‹': 'İ',
'Ý': 'İ',
'ý': 'ı',
'ı': 'ı',
'±': 'ı',
'ý': 'ı',
'Û': 'ı',
'›': 'ı',
'ý': 'ı',
'Þ': 'Ş',
'Åž': 'Ş',
'ÅŸ': 'Ş',
'åÿ': 'Ş',
'Þ': 'Ş',
'þ': 'ş',
'Å?': 'ş',
'ÅŸ': 'ş',
'þ': 'ş',
\x9f': 'ş',
'Ð': 'Ğ',
'Äž': 'Ğ',
'ð': 'ğ',
'Ä?': 'ğ',
'ÄŸ': 'ğ',
'ð': 'ğ',
\x9f': 'ğ',
'Ç': 'Ç',
'Ã?': 'Ç',
'Ç': 'Ç',
'ç': 'ç',
'ç': 'ç',
'Ö': 'Ö',
'Ö': 'Ö',
'ö': 'ö',
'ö': 'ö',
'Ãœ': 'Ü',
'Ü': 'Ü',
'ü': 'ü',
'ã¼': 'ü',
'ü': 'ü',
'ü': 'ü',
"©": "©",
"©": "©",
"©": "©",
"®": "®",
"®": "®",
"®": "®",
"®": "®",
"®": "®",
"™": "™",
"™": "™",
"™": "™",
"™": "™",
">": ">",
">": ">",
">": ">",
">": ">",
"&lt;": "<",
"&LT;": "<",
"&#x0003C;": "<",
"&#60;": "<",
"&semi;": ";",
"&#x0003B;": ";",
"&#59;": ";",
"&amp;": "&",
"&AMP;": "&",
"&#x00026;": "&",
"&#38;": "&",
"&quot;": '"',
"&QUOT;": '"',
"&#x00022;": '"',
"&#34;": '"',
"&num;": "#",
"&#x00023;": "#",
"&#35;": "#",
"&euro;": "€",
\x80\x99": "'",
\x80\x9d": '"',
}
for key, value in tr_map.items():
text = text.replace(key, value)
return text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.