Advertisement
here2share

# translate2eng_demo.py

May 3rd, 2015
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # translate2eng_demo.py
  5.  
  6. print help(unicode.translate)
  7.  
  8. text = u"Åññõýâñçë"
  9.  
  10. print
  11. print text
  12.  
  13. test1 = "Test 1 -- String. abc\x150123\x64xyz!\"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~\xc3"
  14. test2 = "Test 2 -- abc"+any+".123"
  15. test3 = "Test 3 -- &quot;It&apos;s&quot; 9 &gt; 1 &amp; 3 &lt; 7"
  16.  
  17. import string
  18. print test1
  19. print ''.join(filter(lambda x: x in string.printable, test1))
  20. print
  21. print test2
  22. print ''.join(filter(lambda x: x in string.printable, test2))
  23.  
  24. s= test3
  25. s = s.replace("&amp;", "&") # Must be done first!
  26. s = s.replace("&apos;", "'")
  27. s = s.replace("&quot;", '"')
  28. s = s.replace("&lt;", "<")
  29. s = s.replace("&gt;", ">")
  30.  
  31. print
  32. print test3
  33. print s
  34.  
  35. symbols = (u"абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÏÑÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðñòóóôõöùúûüýÿı",
  36.  
  37. u"abvgdeejzijklmnoprstufhzcss_y_euaABVGDEEJZIJKLMNOPRSTUFHZCSS_Y_EUAAAAAAACEEEEIIIIINOOOOOUUUUYaaaaaaceeeeiiiionoooooouuuuyy+")
  38.  
  39. print
  40. print symbols[0]
  41. print
  42. print symbols[1]
  43. print
  44.  
  45.  
  46. tr = {ord(a):ord(b) for a, b in zip(*symbols)}
  47.  
  48. text = u'Тëxт çöñвëртëд фрöм Рüщщïåñ тö Ëñглïщх'
  49. print text.translate(tr)
  50.  
  51. text = u'Åññõýâñçë'
  52. print text.translate(tr)
  53.  
  54. text = u'Text converted from English to Russian'
  55. tr = {ord(a):ord(b) for a, b in zip(*(symbols[1],symbols[0]))}
  56. print text.translate(tr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement