SHARE
TWEET

Invoke-Translit (Bad version)

filimonic Jun 1st, 2020 619 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function Invoke-Translit {
  2.     Param (
  3.         [Parameter(Mandatory=$true,Position=0)]
  4.         [string]$RussianFullName
  5.     )
  6.     $Local:NewFullName = $RussianFullName;
  7.  
  8.     $Local:TranslitTable = @{
  9.         'а' =  @{'Translit' = 'a';};
  10.         'б' =  @{'Translit' = 'b';};
  11.         'в' =  @{'Translit' = 'v';};
  12.         'г' =  @{'Translit' = 'g';};
  13.         'д' =  @{'Translit' = 'd';};
  14.         'е' =  @{'Translit' = 'e';};
  15.         'ё' =  @{'Translit' = 'e';};
  16.         'ж' =  @{'Translit' = 'zh';};
  17.         'з' =  @{'Translit' = 'z';};
  18.         'и' =  @{'Translit' = 'i';};
  19.         'й' =  @{'Translit' = 'y';};
  20.         'к' =  @{'Translit' = 'k';};
  21.         'л' =  @{'Translit' = 'l';};
  22.         'м' =  @{'Translit' = 'm';};
  23.         'н' =  @{'Translit' = 'n';};
  24.         'о' =  @{'Translit' = 'o';};
  25.         'п' =  @{'Translit' = 'p';};
  26.         'р' =  @{'Translit' = 'r';};
  27.         'с' =  @{'Translit' = 's';};
  28.         'т' =  @{'Translit' = 't';};
  29.         'у' =  @{'Translit' = 'u';};
  30.         'ф' =  @{'Translit' = 'f';};
  31.         'х' =  @{'Translit' = 'kh';};
  32.         'ц' =  @{'Translit' = 'ts';};
  33.         'ч' =  @{'Translit' = 'ch';};
  34.         'ш' =  @{'Translit' = 'sh';};
  35.         'щ' =  @{'Translit' = 'sch';};
  36.         'ъ' =  @{'Translit' = '';};
  37.         'ы' =  @{'Translit' = 'y';};
  38.         'ь' =  @{'Translit' = '';};
  39.         'э' =  @{'Translit' = 'e';};
  40.         'ю' =  @{'Translit' = 'yu';};
  41.         'я' =  @{'Translit' = 'ya';};
  42.     }
  43.  
  44.     $local:newCharArray = @();
  45.     $local:charArray = $RussianFullName.ToCharArray()
  46.     foreach ($local:char in $local:charArray) {
  47.         $local:isUpperCase =  [System.Char]::IsUpper($local:char)
  48.         $local:original_char_lowercase = [System.Char]::ToLower($local:char)
  49.         $local:new_char_lowercase_as_string = $local:original_char_lowercase.toString()
  50.         $local:original_char_lowercase_as_string = $local:original_char_lowercase.toString()
  51.         if ($Local:TranslitTable.ContainsKey($local:original_char_lowercase_as_string)) {
  52.             $local:new_char_lowercase_as_string = $Local:TranslitTable[$local:original_char_lowercase_as_string].Translit
  53.         }
  54.  
  55.         $local:new_chars = $local:new_char_lowercase_as_string.toCharArray()
  56.         if ($local:isUpperCase) {
  57.             $local:new_chars[0] = $local:new_chars[0].toString().toUpper().toCharArray()[0]
  58.         }
  59.         $local:newCharArray += @($local:new_chars);
  60.     }
  61.  
  62.    
  63.    
  64.     $local:ret_data = [String]::Join('',$local:newCharArray)
  65.     $local:non_ascii = @( $local:ret_data.ToCharArray() | Where-Object {  
  66.         (
  67.             (
  68.                 ( [System.Int32]$_ ) -gt 126
  69.             ) -or  (
  70.                 ( ( [System.Int32]$_ ) -lt 32 )
  71.             ) ) } )
  72.     if ( $local:non_ascii.Count -gt 0  )  {
  73.         throw "Error! Data contains non-ASCII symbols! : [$($local:non_ascii -join ',')]"
  74.         return $null
  75.     }
  76.     return $local:ret_data
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top