Skip to content

Instantly share code, notes, and snippets.

@vol4ok
Created April 19, 2013 09:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vol4ok/5419325 to your computer and use it in GitHub Desktop.
Save vol4ok/5419325 to your computer and use it in GitHub Desktop.
Translit
String::translit = (->
L =
"А": "A", "а": "a", "Б": "B", "б": "b", "В": "V", "в": "v"
"Г": "G", "г": "g", "Д": "D", "д": "d", "Е": "E", "е": "e"
"Ё": "Yo", "ё": "yo", "Ж": "Zh", "ж": "zh", "З": "Z", "з": "z"
"И": "I", "и": "i", "Й": "Y", "й": "y", "К": "K", "к": "k"
"Л": "L", "л": "l", "М": "M", "м": "m", "Н": "N", "н": "n"
"О": "O", "о": "o", "П": "P", "п": "p", "Р": "R", "р": "r"
"С": "S", "с": "s", "Т": "T", "т": "t", "У": "U", "у": "u"
"Ф": "F", "ф": "f", "Х": "H", "х": "h", "Ц": "Ts", "ц": "ts"
"Ч": "Ch", "ч": "ch", "Ш": "Sh", "ш": "sh", "Щ": "Sch", "щ": "sch"
"Ъ": "\"", "ъ": "\"", "Ы": "Y", "ы": "y", "Ь": "'", "ь": "'"
"Э": "E", "э": "e", "Ю": "Yu", "ю": "yu", "Я": "Ya", "я": "ya"
r = ""
r += k for k of L
r = new RegExp("[" + r + "]", "g")
k = (a) -> if a of L then L[a] else ""
return -> @replace(r, k)
)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment