Maps language detection
This commit is contained in:
parent
f8445285f3
commit
cc4bf7282d
@ -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
|
||||
```
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user