Maps language detection

This commit is contained in:
2020-06-25 00:27:50 +03:00
parent f8445285f3
commit cc4bf7282d
4 changed files with 24 additions and 2 deletions

View File

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

View File

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