Detection trought longest string in map values
This commit is contained in:
@@ -8,6 +8,8 @@ defmodule Localizator.Translator.Microsoft do
|
||||
|
||||
@behaviour Localizator.Translator.Base
|
||||
|
||||
alias Localizator.Commons
|
||||
|
||||
@impl true
|
||||
@spec detect(nil) :: {:error, message}
|
||||
def detect(nil), do: {:error, "Couldn't detect language"}
|
||||
@@ -23,10 +25,7 @@ defmodule Localizator.Translator.Microsoft do
|
||||
|
||||
@impl true
|
||||
@spec detect(map) :: {:ok, locale} | {:error, message}
|
||||
def detect(map) when is_map(map) do
|
||||
{:ok, sample} = Map.fetch(map, List.first(Map.keys(map)))
|
||||
detect(sample)
|
||||
end
|
||||
def detect(map) when is_map(map), do: detect(Commons.first_non_empty_longest_string(map))
|
||||
|
||||
@impl true
|
||||
@spec translate(text, to, optional_from) :: {:ok, text} | {:error, message}
|
||||
|
||||
@@ -8,6 +8,8 @@ defmodule Localizator.Translator.Yandex do
|
||||
|
||||
@behaviour Localizator.Translator.Base
|
||||
|
||||
alias Localizator.Commons
|
||||
|
||||
@impl true
|
||||
@spec detect(nil) :: {:error, message}
|
||||
def detect(nil), do: {:error, "Couldn't detect language"}
|
||||
@@ -23,10 +25,7 @@ defmodule Localizator.Translator.Yandex do
|
||||
|
||||
@impl true
|
||||
@spec detect(map) :: {:ok, locale} | {:error, message}
|
||||
def detect(map) when is_map(map) do
|
||||
{:ok, sample} = Map.fetch(map, List.first(Map.keys(map)))
|
||||
detect(sample)
|
||||
end
|
||||
def detect(map) when is_map(map), do: detect(Commons.first_non_empty_longest_string(map))
|
||||
|
||||
@impl true
|
||||
@spec translate(text, to, optional_from) :: {:ok, text} | {:error, message}
|
||||
|
||||
Reference in New Issue
Block a user