function global:TranslitToLAT
{
param([string]$inString)
$Translit_To_LAT = @{
[char]'а' = "a"
[char]'А' = "a"
[char]'б' = "b"
[char]'Б' = "b"
[char]'в' = "v"
[char]'В' = "v"
[char]'г' = "g"
[char]'Г' = "g"
[char]'д' = "d"
[char]'Д' = "d"
[char]'е' = "e"
[char]'Е' = "e"
[char]'ё' = "e"
[char]'Ё' = "e"
[char]'ж' = "zh"
[char]'Ж' = "zh"
[char]'з' = "z"
[char]'З' = "z"
[char]'и' = "i"
[char]'И' = "i"
[char]'й' = "i"
[char]'Й' = "i"
[char]'к' = "k"
[char]'К' = "k"
[char]'л' = "l"
[char]'Л' = "l"
[char]'м' = "m"
[char]'М' = "m"
[char]'н' = "n"
[char]'Н' = "n"
[char]'о' = "o"
[char]'О' = "o"
[char]'п' = "p"
[char]'П' = "p"
[char]'р' = "r"
[char]'Р' = "r"
[char]'с' = "s"
[char]'С' = "s"
[char]'т' = "t"
[char]'Т' = "t"
[char]'у' = "u"
[char]'У' = "u"
[char]'ф' = "f"
[char]'Ф' = "f"
[char]'х' = "kh"
[char]'Х' = "kh"
[char]'ц' = "tc"
[char]'Ц' = "tc"
[char]'ч' = "ch"
[char]'Ч' = "ch"
[char]'ш' = "sh"
[char]'Ш' = "sh"
[char]'щ' = "shch"
[char]'Щ' = "shch"
[char]'ъ' = "" # "``"
[char]'Ъ' = "" # "``"
[char]'ы' = "y" # "y`"
[char]'Ы' = "y" # "Y`"
[char]'ь' = "" # "`"
[char]'Ь' = "" # "`"
[char]'э' = "e" # "e`"
[char]'Э' = "e" # "E`"
[char]'ю' = "iu"
[char]'Ю' = "iu"
[char]'я' = "ia"
[char]'Я' = "ia"
[char]' ' = "_"
}
$outChars=""
foreach ($c in $inChars = $inString.ToCharArray())
{
if ($Translit_To_LAT[$c] -cne $Null )
{$outChars += $Translit_To_LAT[$c]}
else
{$outChars += $c}
}
Write-Output $outChars
}
$text = Read-Host "Введите текст"
$log = TranslitToLAT $text
$log
function Convert2Latin($inString) {
# Обрезаем пустые пробелы по краям
$inString = $inString.Trim()
# Определяем таблицу соответствия
$char_ru="а","А","б","Б","в","В","г","Г","д","Д","е","Е","ё","Ё","ж", "Ж", "з","З","и","И","й","Й", "к","К","л","Л","м","М","н","Н","о","О","п","П","р","Р","с","С","т","Т","у","У","ф","Ф","х", "Х", "ц", "Ц", "ч", "Ч", "ш", "Ш", "щ", "Щ","ъ","Ъ","ы","Ы","ь","Ь","э","Э","ю", "Ю", "я", "Я"
$char_en="a","A","b","B","v","V","g","G","d","D","e","E","e","E","zh","Zh","z","Z","i","I","y","Iy","k","K","l","L","m","M","n","N","o","O","p","P","r","R","s","S","t","T","u","U","f","F","kh","Kh","ts","Ts","ch","Ch","sh","Sh","sch","Sch","","","y","Y","","", "e","E","yu","Yu","ya","Ya"
$TempString = ""
# Перебираем слово по буквам
for ($i = 0; $i -lt $inString.Length; $i++)
{
$t = -1
# Выясняем позицию заменямой буквы в массиве
Do {$t = $t+1}
Until (($inString[$i] -ceq $char_ru[$t]) -or ($t -eq 100))
# Дополняем строку конвертированного одновременно производя замену русской буквы на английскую
$TempString = $TempString + ($inString[$i] -creplace $char_ru[$t], $char_en[$t])
}
return $TempString
}
.
( 'вий', 'vy' ),
( 'гий', 'gy' ),
( 'дий', 'dy' ),
( 'ний', 'ny' ),
( 'сий', 'sy' ),
( 'тий', 'ty' ),
( 'жд', 'zd' ),
( 'ай', 'ay' ),
( 'ей', 'ey' ),
( 'ёй', 'ey' ),
( 'ий', 'iy' ),
( 'ия', 'ia' ),
( 'ой', 'oy' ),
( 'уй', 'uy' ),
( 'ый', 'uy' ),
( 'эй', 'ey' ),
( 'ья', 'ia' ),
( 'ье', 'ye' ),
( 'ьё', 'ye' ),
( 'ьа', 'ia' ),
( 'ьи', 'yi' ),
( 'ьо', 'yo' ),
( 'ьу', 'yu' ),
( 'ьы', 'yy' ),
( 'ьэ', 'ye' ),
( 'ью', 'yu' ),
( 'кс', 'x' ),
( 'юй', 'yuy' ),
( 'яй', 'yay' ),
( 'лю', 'liu' ),
( 'ж', 'zh' ),
( 'х', 'kh' ),
( 'ц', 'ts' ),
( 'ч', 'ch' ),
( 'ш', 'sh' ),
( 'я', 'ya' ),
( 'ю', 'yu' ),
( 'щ', 'shch' ),
( 'ъ', '' ),
( 'ь', '' ),
( 'а', 'a' ),
( 'б', 'b' ),
( 'в', 'v' ),
( 'г', 'g' ),
( 'д', 'd' ),
( 'е', 'e' ),
( 'ё', 'e' ),
( 'з', 'z' ),
( 'и', 'i' ),
( 'й', 'y' ),
( 'к', 'k' ),
( 'л', 'l' ),
( 'м', 'm' ),
( 'н', 'n' ),
( 'о', 'o' ),
( 'п', 'p' ),
( 'р', 'r' ),
( 'с', 's' ),
( 'т', 't' ),
( 'у', 'u' ),
( 'ф', 'f' ),
( 'ы', 'y' ),
( 'э', 'e' )