2020-06-07 17:00:56 +03:00

115 lines
2.0 KiB
Elixir
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

defmodule Localizator.Translitor.RU do
@moduledoc """
Translit module for Russian language. By ICAO Standard (2012—2016)
"""
@locale "ru"
@table %{
" " => " ",
"А" => "A",
"Б" => "B",
"В" => "V",
"Г" => "G",
"Д" => "D",
"Е" => "E",
"Ё" => "E",
"Ж" => "Zh",
"З" => "Z",
"И" => "I",
"Й" => "I",
"К" => "K",
"Л" => "L",
"М" => "M",
"Н" => "N",
"О" => "O",
"П" => "P",
"Р" => "R",
"С" => "S",
"Т" => "T",
"У" => "U",
"Ф" => "F",
"Х" => "Kh",
"Ц" => "Ts",
"Ч" => "Ch",
"Ш" => "Sh",
"Щ" => "Shch",
"Ъ" => "",
"Ы" => "Y",
"Ь" => "",
"Э" => "E",
"Ю" => "Iu",
"Я" => "Ia",
"а" => "a",
"б" => "b",
"в" => "v",
"г" => "g",
"д" => "d",
"е" => "e",
"ё" => "e",
"ж" => "zh",
"з" => "z",
"и" => "i",
"й" => "i",
"к" => "k",
"л" => "l",
"м" => "m",
"н" => "n",
"о" => "o",
"п" => "p",
"р" => "r",
"с" => "s",
"т" => "t",
"у" => "u",
"ф" => "f",
"х" => "kh",
"ц" => "ts",
"ч" => "ch",
"ш" => "sh",
"щ" => "shch",
"ъ" => "",
"ы" => "y",
"ь" => "",
"э" => "e",
"ю" => "iu",
"я" => "ia"
}
@typedoc """
Plain Text
"""
@type text :: String.t()
@typedoc """
Locale
"""
@type locale :: String.t()
@behaviour Localizator.Translitor.Base
@impl true
@spec locale() :: {:ok, locale}
def locale(), do: @locale
@doc """
A russian to english transliteration
## Example
``elixir
iex> Localizator.Translitor.RU.convert("Роман Шевченко")
"Roman Shevchenko"
``
"""
@impl true
@spec convert(text) :: text
def convert(text) when is_bitstring(text) do
text
|> String.graphemes()
|> Enum.map(&convert_letter/1)
|> Enum.join()
end
defp convert_letter(letter) do
case Map.get(@table, letter) do
nil -> letter
latin -> latin
end
end
end