Locale added

This commit is contained in:
2020-06-07 22:01:46 +03:00
parent f3b057a7be
commit 21b9ed364e
6 changed files with 51 additions and 34 deletions

View File

@@ -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

View File

@@ -1,5 +1,5 @@
defmodule Localizator.Translator do
alias Localizator.Translator.Direction
alias Localizator.Direction
@typedoc """
Locale