Locale added
This commit is contained in:
parent
f3b057a7be
commit
21b9ed364e
4
.iex.exs
4
.iex.exs
@ -1,6 +1,8 @@
|
||||
alias Localizator.Parser
|
||||
alias Localizator.Parser.{Base, JSON}
|
||||
alias Localizator.Locale
|
||||
alias Localizator.Direction
|
||||
alias Localizator.Translator
|
||||
alias Localizator.Translator.{Yandex, Direction}
|
||||
alias Localizator.Translator.{Yandex}
|
||||
alias Localizator.Translitor
|
||||
alias Localizator.Translitor.{UK, BE, RU}
|
||||
|
32
lib/direction/direction.ex
Normal file
32
lib/direction/direction.ex
Normal file
@ -0,0 +1,32 @@
|
||||
defmodule Localizator.Direction do
|
||||
alias Localizator.Commons
|
||||
alias Localizator.Locale
|
||||
|
||||
defstruct [:from, :to]
|
||||
|
||||
@typedoc """
|
||||
Locale
|
||||
"""
|
||||
@type locale :: String.t() | Atom.t()
|
||||
@type from :: locale
|
||||
@type from_may_be_nil :: from | nil
|
||||
@type to :: locale
|
||||
@type direction :: {from, to} | to | %{from: from, to: to} | %{to: to}
|
||||
@type direction_struct :: %{to: to, from: from_may_be_nil}
|
||||
|
||||
@spec get(direction) :: direction_struct
|
||||
def get(direction) do
|
||||
direction_map =
|
||||
case direction do
|
||||
[from: from, to: to] -> %{to: Locale.normalize(to), from: Locale.normalize(from)}
|
||||
[from, to] -> %{to: Locale.normalize(to), from: Locale.normalize(from)}
|
||||
{from, to} -> %{to: Locale.normalize(to), from: Locale.normalize(from)}
|
||||
%{from: from, to: to} -> %{to: Locale.normalize(to), from: Locale.normalize(from)}
|
||||
%{to: to} -> %{to: Locale.normalize(to), from: nil}
|
||||
[to: to] -> %{to: Locale.normalize(to), from: nil}
|
||||
to -> %{to: Locale.normalize(to), from: nil}
|
||||
end
|
||||
|
||||
Commons.struct_from_map(direction_map, as: %__MODULE__{})
|
||||
end
|
||||
end
|
14
lib/locale/locale.ex
Normal file
14
lib/locale/locale.ex
Normal file
@ -0,0 +1,14 @@
|
||||
defmodule Localizator.Locale do
|
||||
@typedoc """
|
||||
Locale
|
||||
"""
|
||||
@type locale :: String.t() | Atom.t()
|
||||
|
||||
@typedoc """
|
||||
Normalized Locale
|
||||
"""
|
||||
@type normalized_locale :: String.t()
|
||||
|
||||
@spec normalize(locale) :: normalized_locale
|
||||
def normalize(locale), do: "#{locale}"
|
||||
end
|
@ -1,31 +0,0 @@
|
||||
defmodule Localizator.Translator.Direction do
|
||||
alias Localizator.Commons
|
||||
|
||||
defstruct [:from, :to]
|
||||
|
||||
@typedoc """
|
||||
Locale
|
||||
"""
|
||||
@type locale :: String.t() | Atom.t()
|
||||
@type from :: locale
|
||||
@type from_may_be_nil :: from | nil
|
||||
@type to :: locale
|
||||
@type direction :: {from, to} | to | %{from: from, to: to} | %{to: to}
|
||||
@type direction_struct :: %{to: to, from: from_may_be_nil}
|
||||
|
||||
@spec get(direction) :: direction_struct
|
||||
def get(direction) do
|
||||
direction_map =
|
||||
case direction do
|
||||
[from: from, to: to] -> %{to: "#{to}", from: "#{from}"}
|
||||
[from, to] -> %{to: "#{to}", from: "#{from}"}
|
||||
{from, to} -> %{to: "#{to}", from: "#{from}"}
|
||||
%{from: from, to: to} -> %{to: "#{to}", from: "#{from}"}
|
||||
%{to: to} -> %{to: "#{to}", from: nil}
|
||||
[to: to] -> %{to: "#{to}", from: nil}
|
||||
to -> %{to: "#{to}", from: nil}
|
||||
end
|
||||
|
||||
Commons.struct_from_map(direction_map, as: %__MODULE__{})
|
||||
end
|
||||
end
|
@ -1,5 +1,5 @@
|
||||
defmodule Localizator.Translator do
|
||||
alias Localizator.Translator.Direction
|
||||
alias Localizator.Direction
|
||||
|
||||
@typedoc """
|
||||
Locale
|
||||
|
@ -23,6 +23,6 @@ defmodule Localizator.Translitor.Base do
|
||||
"""
|
||||
@type message :: String.t()
|
||||
|
||||
@callback convert(text) :: {:ok, translited} | {:error, message}
|
||||
@callback convert(text) :: {:ok, translited} | {:incompletely, translited} | {:error, message}
|
||||
@callback locale() :: {:ok, locale}
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user