Maps language detection
This commit is contained in:
@@ -17,6 +17,17 @@ defmodule Localizator.Translator.Microsoft do
|
||||
end
|
||||
end
|
||||
|
||||
@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)))
|
||||
|
||||
case MicrosoftTranslator.detect(sample) do
|
||||
%{languageCode: locale} -> {:ok, locale}
|
||||
%{} -> {:error, "Couldn't detect language"}
|
||||
end
|
||||
end
|
||||
|
||||
@impl true
|
||||
@spec translate(text, to, optional_from) :: {:ok, text} | {:error, message}
|
||||
def translate(text, to, from \\ nil)
|
||||
|
||||
@@ -17,6 +17,17 @@ defmodule Localizator.Translator.Yandex do
|
||||
end
|
||||
end
|
||||
|
||||
@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)))
|
||||
|
||||
case YandexTranslate.detect(sample) do
|
||||
%{languageCode: locale} -> {:ok, locale}
|
||||
%{} -> {:error, "Couldn't detect language"}
|
||||
end
|
||||
end
|
||||
|
||||
@impl true
|
||||
@spec translate(text, to, optional_from) :: {:ok, text} | {:error, message}
|
||||
def translate(text, to, from \\ nil)
|
||||
|
||||
Reference in New Issue
Block a user