Advertisement
urosevic

SublimeText3: Serbian Cyrillic to Latin

Jan 11th, 2015
293
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # WTF: Convert Serbian Cyrillic to Latin script
  2. # Author: Aleksandar Urosevic (urosevic.net)
  3. # Written for: Sublime Text 3
  4. # Goal: learning Python for ST
  5.  
  6. import sublime, sublime_plugin
  7.  
  8. class CyrLatAllTranslitCommand(sublime_plugin.TextCommand):
  9.  
  10.     def run(self, edit):
  11.  
  12.         # get self view
  13.         view = self.view
  14.  
  15.         # define region to replace (whole file)
  16.         region = sublime.Region(0, view.size())
  17.         content = view.substr(region)
  18.  
  19.         # lowercase characters
  20.         content = content.replace(u"а", "a")
  21.         content = content.replace(u"б", "b")
  22.         content = content.replace(u"в", "v")
  23.         content = content.replace(u"г", "g")
  24.         content = content.replace(u"д", "d")
  25.         content = content.replace(u"ђ", "đ")
  26.         content = content.replace(u"е", "e")
  27.         content = content.replace(u"ж", "ž")
  28.         content = content.replace(u"з", "z")
  29.         content = content.replace(u"и", "i")
  30.         content = content.replace(u"ј", "j")
  31.         content = content.replace(u"к", "k")
  32.         content = content.replace(u"л", "l")
  33.         content = content.replace(u"љ", "lj")
  34.         content = content.replace(u"м", "m")
  35.         content = content.replace(u"н", "n")
  36.         content = content.replace(u"њ", "nj")
  37.         content = content.replace(u"о", "o")
  38.         content = content.replace(u"п", "p")
  39.         content = content.replace(u"р", "r")
  40.         content = content.replace(u"с", "s")
  41.         content = content.replace(u"т", "t")
  42.         content = content.replace(u"ћ", "ć")
  43.         content = content.replace(u"у", "u")
  44.         content = content.replace(u"ф", "f")
  45.         content = content.replace(u"х", "h")
  46.         content = content.replace(u"ц", "c")
  47.         content = content.replace(u"ч", "č")
  48.         content = content.replace(u"џ", "dž")
  49.         content = content.replace(u"ш", "š")
  50.  
  51.         # uppercase characters
  52.         content = content.replace(u"А", "A")
  53.         content = content.replace(u"Б", "B")
  54.         content = content.replace(u"В", "V")
  55.         content = content.replace(u"Г", "G")
  56.         content = content.replace(u"Д", "D")
  57.         content = content.replace(u"Ђ", "Đ")
  58.         content = content.replace(u"Е", "E")
  59.         content = content.replace(u"Ж", "Ž")
  60.         content = content.replace(u"З", "Z")
  61.         content = content.replace(u"И", "I")
  62.         content = content.replace(u"Ј", "J")
  63.         content = content.replace(u"К", "K")
  64.         content = content.replace(u"Л", "L")
  65.         content = content.replace(u"Љ", "Lj")
  66.         content = content.replace(u"М", "M")
  67.         content = content.replace(u"Н", "N")
  68.         content = content.replace(u"Њ", "Nj")
  69.         content = content.replace(u"О", "O")
  70.         content = content.replace(u"П", "P")
  71.         content = content.replace(u"Р", "R")
  72.         content = content.replace(u"С", "S")
  73.         content = content.replace(u"Т", "T")
  74.         content = content.replace(u"Ћ", "Ć")
  75.         content = content.replace(u"У", "U")
  76.         content = content.replace(u"Ф", "F")
  77.         content = content.replace(u"Х", "H")
  78.         content = content.replace(u"Ц", "C")
  79.         content = content.replace(u"Ч", "Č")
  80.         content = content.replace(u"Џ", "Dž")
  81.         content = content.replace(u"Ш", "Š")
  82.  
  83.         # uppercase two-letter chars
  84.         content = content.replace(u"NjA", "NJA")
  85.         content = content.replace(u"NjE", "NJE")
  86.         content = content.replace(u"NjI", "NJI")
  87.         content = content.replace(u"NjO", "NJO")
  88.         content = content.replace(u"NjU", "NJU")
  89.         content = content.replace(u"ANj", "ANJ")
  90.         content = content.replace(u"ENj", "ENJ")
  91.         content = content.replace(u"INj", "INJ")
  92.         content = content.replace(u"ONj", "ONJ")
  93.         content = content.replace(u"UNj", "UNJ")
  94.  
  95.         content = content.replace(u"LjA", "LJA")
  96.         content = content.replace(u"LjE", "LJE")
  97.         content = content.replace(u"LjI", "LJI")
  98.         content = content.replace(u"LjO", "LJO")
  99.         content = content.replace(u"LjU", "LJU")
  100.         content = content.replace(u"ALj", "ALJ")
  101.         content = content.replace(u"ELj", "ELJ")
  102.         content = content.replace(u"ILj", "ILJ")
  103.         content = content.replace(u"OLj", "OLJ")
  104.         content = content.replace(u"ULj", "ULJ")
  105.  
  106.         content = content.replace(u"DžA", "DŽA")
  107.         content = content.replace(u"DžE", "DŽE")
  108.         content = content.replace(u"DžI", "DŽI")
  109.         content = content.replace(u"DžO", "DŽO")
  110.         content = content.replace(u"DžU", "DŽU")
  111.         content = content.replace(u"ADž", "ADŽ")
  112.         content = content.replace(u"EDž", "EDŽ")
  113.         content = content.replace(u"IDž", "IDŽ")
  114.         content = content.replace(u"ODž", "ODŽ")
  115.         content = content.replace(u"UDž", "UDŽ")
  116.  
  117.         # update content in view
  118.         view.replace(edit, region, content)
  119.  
  120.         # close edit buffer
  121.         view.end_edit(edit)
Advertisement
RAW Paste Data Copied
Advertisement