Maps language detection

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

View File

@ -10,7 +10,7 @@ by adding `localizator` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:localizator, "~> 0.1.5"}
{:localizator, "~> 0.1.6"}
]
end
```

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)

View File

@ -4,7 +4,7 @@ defmodule Localizator.MixProject do
def project do
[
app: :localizator,
version: "0.1.5",
version: "0.1.6",
elixir: "~> 1.10",
start_permanent: Mix.env() == :prod,
deps: deps()