How should I go about implementing a method that gets a String composed of Latin characters to translate it into a String composed of a different set of characters, let's say Cyrillic.
Here's how it's done in PHP for example:
function latin_to_cyrillic($string)
{
$array = array(
"а" => "a",
"б" => "b",
"в" => "v",
"г" => "g",
"д" => "d",
"е" => "e",
"ж" => "zh",
"з" => "z",
"и" => "i",
"й" => "y",
"к" => "k",
"л" => "l",
"м" => "m",
"н" => "n",
"о" => "o",
"п" => "p",
"р" => "r",
"с" => "s",
"т" => "t",
"у" => "u",
"ф" => "f",
"х" => "h",
"ц" => "ts",
"ч" => "ch",
"ш" => "sh",
"щ" => "sht",
"ь" => "y",
"ъ" => "a",
"ю" => "yu",
"я" => "ya",
"А" => "A",
"Б" => "B",
"В" => "V",
"Г" => "G",
"Д" => "D",
"Е" => "E",
"Ж" => "Zh",
"З" => "Z",
"И" => "I",
"Й" => "Y",
"К" => "K",
"Л" => "L",
"М" => "M",
"Н" => "N",
"О" => "O",
"П" => "P",
"Р" => "R",
"С" => "S",
"Т" => "T",
"У" => "U",
"Ф" => "F",
"Х" => "H",
"Ц" => "Ts",
"Ч" => "Ch",
"Ш" => "Sh",
"Щ" => "Sht",
"Ь" => "Y",
"Ъ" => "A",
"Ю" => "Yu",
"Я" => "Ya",
"–" => "-");
return str_replace(array_values($array), array_keys($array), $string);
}
See Question&Answers more detail:
os