Public/ConvertTo-Translit.ps1
function ConvertTo-Translit { <# .Synopsis Преобразование сроки кирилических символов в строку латинских символов .Description Преобразование сроки кирилических символов в строку латинских символов .Parameter Value Строка для преобразования .Example PS C:\> ConvertTo-Translit -Value 'Евлапмия Романова' Evlapmiya Romanova .Notes .Inputs Строка кирилицей .Outputs Строка латиницей #> [CmdletBinding()] [OutputType([System.Int32])] param( [Parameter(Mandatory = $true, ValueFromPipeLine = $true, Position = 0)] [System.String] $Value ) Begin { $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]'й' = "y" [char]'Й' = "Y" [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]'ц' = "ts" [char]'Ц' = "Ts" [char]'ч' = "ch" [char]'Ч' = "Ch" [char]'ш' = "sh" [char]'Ш' = "Sh" [char]'щ' = "sch" [char]'Щ' = "Sch" [char]'ъ' = "787" # "``" [char]'Ъ' = "787" # "``" [char]'ы' = "y" # "y`" [char]'Ы' = "Y" # "Y`" [char]'ь' = "787" # "`" [char]'Ь' = "787" # "`" [char]'э' = "e" # "e`" [char]'Э' = "E" # "E`" [char]'ю' = "yu" [char]'Ю' = "Yu" [char]'я' = "ya" [char]'Я' = "Ya" } $outChars = "" } Process { try { $inChars = $Value.ToCharArray() foreach ($c in $inChars) { if ($Null -cne $Translit_To_LAT[$c]) { $outChars += $Translit_To_LAT[$c] -replace "787", "" } else { $outChars += $c } } } catch { #$PSCmdlet.ThrowTerminatingError($PSItem) Write-Error -Exception $PSItem.Exeception } } End { return $outChars } } |