Compare commits
No commits in common. "master" and "0.1.12" have entirely different histories.
@ -10,7 +10,7 @@ by adding `localizator` to your list of dependencies in `mix.exs`:
|
|||||||
```elixir
|
```elixir
|
||||||
def deps do
|
def deps do
|
||||||
[
|
[
|
||||||
{:localizator, "~> 0.1.17"}
|
{:localizator, "~> 0.1.11"}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
@ -5,17 +5,6 @@ defmodule Localizator.Commons do
|
|||||||
String.match?(string, @html_regex)
|
String.match?(string, @html_regex)
|
||||||
end
|
end
|
||||||
|
|
||||||
def first_non_empty_longest_string(map) when is_map(map) do
|
|
||||||
map
|
|
||||||
|> Map.values()
|
|
||||||
|> Enum.reject(&is_nil(&1))
|
|
||||||
|> Enum.filter(&is_binary(&1))
|
|
||||||
|> Enum.map(&String.trim(&1))
|
|
||||||
|> Enum.reject(&(&1 == ""))
|
|
||||||
|> Enum.sort(&(String.length(&1) >= String.length(&2)))
|
|
||||||
|> List.first()
|
|
||||||
end
|
|
||||||
|
|
||||||
def struct_from_map(a_map, as: a_struct) do
|
def struct_from_map(a_map, as: a_struct) do
|
||||||
# Find the keys within the map
|
# Find the keys within the map
|
||||||
keys =
|
keys =
|
||||||
|
@ -8,12 +8,6 @@ defmodule Localizator.Translator.Microsoft do
|
|||||||
|
|
||||||
@behaviour Localizator.Translator.Base
|
@behaviour Localizator.Translator.Base
|
||||||
|
|
||||||
alias Localizator.Commons
|
|
||||||
|
|
||||||
@impl true
|
|
||||||
@spec detect(nil) :: {:error, message}
|
|
||||||
def detect(nil), do: {:error, "Couldn't detect language"}
|
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
@spec detect(text) :: {:ok, locale} | {:error, message}
|
@spec detect(text) :: {:ok, locale} | {:error, message}
|
||||||
def detect(text) when is_bitstring(text) do
|
def detect(text) when is_bitstring(text) do
|
||||||
@ -25,7 +19,14 @@ defmodule Localizator.Translator.Microsoft do
|
|||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
@spec detect(map) :: {:ok, locale} | {:error, message}
|
@spec detect(map) :: {:ok, locale} | {:error, message}
|
||||||
def detect(map) when is_map(map), do: detect(Commons.first_non_empty_longest_string(map))
|
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
|
@impl true
|
||||||
@spec translate(text, to, optional_from) :: {:ok, text} | {:error, message}
|
@spec translate(text, to, optional_from) :: {:ok, text} | {:error, message}
|
||||||
@ -44,9 +45,6 @@ defmodule Localizator.Translator.Microsoft do
|
|||||||
|> List.first()
|
|> List.first()
|
||||||
|> Map.fetch(:text)
|
|> Map.fetch(:text)
|
||||||
|
|
||||||
%{error: %{message: message}} ->
|
|
||||||
{:error, message}
|
|
||||||
|
|
||||||
%{message: message} ->
|
%{message: message} ->
|
||||||
{:error, message}
|
{:error, message}
|
||||||
end
|
end
|
||||||
|
@ -51,9 +51,6 @@ defmodule Localizator.Translator do
|
|||||||
translate(source, map.to, map.from, translator)
|
translate(source, map.to, map.from, translator)
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec translate(nil, to, from_may_be_nil, translator) :: result
|
|
||||||
def translate(empty, _to, _from, _translator) when is_nil(empty), do: nil
|
|
||||||
|
|
||||||
@spec translate(String.t(), to, from_may_be_nil, translator) :: result
|
@spec translate(String.t(), to, from_may_be_nil, translator) :: result
|
||||||
def translate(string, to, from, translator) when is_binary(string) do
|
def translate(string, to, from, translator) when is_binary(string) do
|
||||||
case Commons.is_html?(string) do
|
case Commons.is_html?(string) do
|
||||||
|
@ -8,12 +8,6 @@ defmodule Localizator.Translator.Yandex do
|
|||||||
|
|
||||||
@behaviour Localizator.Translator.Base
|
@behaviour Localizator.Translator.Base
|
||||||
|
|
||||||
alias Localizator.Commons
|
|
||||||
|
|
||||||
@impl true
|
|
||||||
@spec detect(nil) :: {:error, message}
|
|
||||||
def detect(nil), do: {:error, "Couldn't detect language"}
|
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
@spec detect(text) :: {:ok, locale} | {:error, message}
|
@spec detect(text) :: {:ok, locale} | {:error, message}
|
||||||
def detect(text) when is_bitstring(text) do
|
def detect(text) when is_bitstring(text) do
|
||||||
@ -25,7 +19,14 @@ defmodule Localizator.Translator.Yandex do
|
|||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
@spec detect(map) :: {:ok, locale} | {:error, message}
|
@spec detect(map) :: {:ok, locale} | {:error, message}
|
||||||
def detect(map) when is_map(map), do: detect(Commons.first_non_empty_longest_string(map))
|
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
|
@impl true
|
||||||
@spec translate(text, to, optional_from) :: {:ok, text} | {:error, message}
|
@spec translate(text, to, optional_from) :: {:ok, text} | {:error, message}
|
||||||
|
4
mix.exs
4
mix.exs
@ -4,7 +4,7 @@ defmodule Localizator.MixProject do
|
|||||||
def project do
|
def project do
|
||||||
[
|
[
|
||||||
app: :localizator,
|
app: :localizator,
|
||||||
version: "0.1.17",
|
version: "0.1.11",
|
||||||
elixir: "~> 1.10",
|
elixir: "~> 1.10",
|
||||||
start_permanent: Mix.env() == :prod,
|
start_permanent: Mix.env() == :prod,
|
||||||
deps: deps()
|
deps: deps()
|
||||||
@ -22,7 +22,7 @@ defmodule Localizator.MixProject do
|
|||||||
defp deps do
|
defp deps do
|
||||||
[
|
[
|
||||||
{:yandex_translate, "~> 0.4.1"},
|
{:yandex_translate, "~> 0.4.1"},
|
||||||
{:microsoft_translator, "~> 0.1.5"},
|
{:microsoft_translator, "~> 0.1.4"},
|
||||||
|
|
||||||
# Parsers/generators
|
# Parsers/generators
|
||||||
{:meeseeks, "~> 0.15.1"},
|
{:meeseeks, "~> 0.15.1"},
|
||||||
|
2
mix.lock
2
mix.lock
@ -19,7 +19,7 @@
|
|||||||
"meeseeks": {:hex, :meeseeks, "0.15.1", "148d5d9ea879cdb415b8bc4162ac5528f9a2fe42fbfe1802c681a2842cb1c0a4", [:mix], [{:meeseeks_html5ever, "~> 0.12.1", [hex: :meeseeks_html5ever, repo: "hexpm", optional: false]}], "hexpm", "5589957b7cca75e6683cecc308253d7854f43b07806939d7031b81ca6e8abd98"},
|
"meeseeks": {:hex, :meeseeks, "0.15.1", "148d5d9ea879cdb415b8bc4162ac5528f9a2fe42fbfe1802c681a2842cb1c0a4", [:mix], [{:meeseeks_html5ever, "~> 0.12.1", [hex: :meeseeks_html5ever, repo: "hexpm", optional: false]}], "hexpm", "5589957b7cca75e6683cecc308253d7854f43b07806939d7031b81ca6e8abd98"},
|
||||||
"meeseeks_html5ever": {:hex, :meeseeks_html5ever, "0.12.1", "718fab10d05b83204524a518b2b88caa37ba6a6e02f82e80d6a7bc47552fb54a", [:mix], [{:rustler, "~> 0.21.0", [hex: :rustler, repo: "hexpm", optional: false]}], "hexpm", "11489094637f49a26bad4610a9138352c8d229339d888169cb35b08cdfd8861a"},
|
"meeseeks_html5ever": {:hex, :meeseeks_html5ever, "0.12.1", "718fab10d05b83204524a518b2b88caa37ba6a6e02f82e80d6a7bc47552fb54a", [:mix], [{:rustler, "~> 0.21.0", [hex: :rustler, repo: "hexpm", optional: false]}], "hexpm", "11489094637f49a26bad4610a9138352c8d229339d888169cb35b08cdfd8861a"},
|
||||||
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
|
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
|
||||||
"microsoft_translator": {:hex, :microsoft_translator, "0.1.5", "15774b7d28a3174669283f455b2cac4f404dafab11dd2da227828d4444dcce90", [:mix], [{:castore, "~> 0.1.6", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.2.0", [hex: :jason, repo: "hexpm", optional: false]}, {:joken, "~> 2.2.0", [hex: :joken, repo: "hexpm", optional: false]}, {:jose, "~> 1.10.1", [hex: :jose, repo: "hexpm", optional: false]}, {:mojito, "~> 0.7.3", [hex: :mojito, repo: "hexpm", optional: false]}], "hexpm", "fb366a7a49ee69eed93cd2f03e8312186a79365a9c34c99cd43681c86f134df7"},
|
"microsoft_translator": {:hex, :microsoft_translator, "0.1.4", "bb764e61a43ca62a1e78098f15d08f3d69466ca6685a2ff8bb2476b740a75e17", [:mix], [{:castore, "~> 0.1.6", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.2.0", [hex: :jason, repo: "hexpm", optional: false]}, {:joken, "~> 2.2.0", [hex: :joken, repo: "hexpm", optional: false]}, {:jose, "~> 1.10.1", [hex: :jose, repo: "hexpm", optional: false]}, {:mojito, "~> 0.7.3", [hex: :mojito, repo: "hexpm", optional: false]}], "hexpm", "6cc91c5bbad23783a7016c608d212bde2e1389212f895d7951fd03e27dce3416"},
|
||||||
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
|
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
|
||||||
"mint": {:hex, :mint, "1.1.0", "1fd0189edd9e3ffdbd7fcd8bc3835902b987a63ec6c4fd1aa8c2a56e2165f252", [:mix], [{:castore, "~> 0.1.0", [hex: :castore, repo: "hexpm", optional: true]}], "hexpm", "5bfd316c3789340b682d5679a8116bcf2112e332447bdc20c1d62909ee45f48d"},
|
"mint": {:hex, :mint, "1.1.0", "1fd0189edd9e3ffdbd7fcd8bc3835902b987a63ec6c4fd1aa8c2a56e2165f252", [:mix], [{:castore, "~> 0.1.0", [hex: :castore, repo: "hexpm", optional: true]}], "hexpm", "5bfd316c3789340b682d5679a8116bcf2112e332447bdc20c1d62909ee45f48d"},
|
||||||
"mojito": {:hex, :mojito, "0.7.3", "7356f3b7697d79520a243b48cf0bf8bd1152b2e9cdb6ff7cf22cd0769f32dd40", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}], "hexpm", "433479d8ef1c882fafe864ac6d7b08249f321fc46bdcc8db78691bc1ddcf234a"},
|
"mojito": {:hex, :mojito, "0.7.3", "7356f3b7697d79520a243b48cf0bf8bd1152b2e9cdb6ff7cf22cd0769f32dd40", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}], "hexpm", "433479d8ef1c882fafe864ac6d7b08249f321fc46bdcc8db78691bc1ddcf234a"},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user