mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-12-30 04:14:57 +00:00
Return empty string in the event of no detected language
This commit is contained in:
parent
145c73076d
commit
f1e66b39c7
|
@ -39,9 +39,9 @@ defmodule Pleroma.Akkoma.Translators.LibreTranslate do
|
||||||
detected =
|
detected =
|
||||||
if Map.has_key?(body, "detectedLanguage") do
|
if Map.has_key?(body, "detectedLanguage") do
|
||||||
get_in(body, ["detectedLanguage", "language"])
|
get_in(body, ["detectedLanguage", "language"])
|
||||||
else
|
else
|
||||||
from_language
|
from_language || ""
|
||||||
end
|
end
|
||||||
|
|
||||||
{:ok, detected, translated}
|
{:ok, detected, translated}
|
||||||
else
|
else
|
||||||
|
|
|
@ -133,5 +133,21 @@ defmodule Pleroma.Akkoma.Translators.LibreTranslateTest do
|
||||||
assert {:error, "libre_translate: request failed (code 400)"} =
|
assert {:error, "libre_translate: request failed (code 400)"} =
|
||||||
LibreTranslate.translate("ギュギュ握りつぶしちゃうぞ", nil, "zoop")
|
LibreTranslate.translate("ギュギュ握りつぶしちゃうぞ", nil, "zoop")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "should work when no detected language is received" do
|
||||||
|
Tesla.Mock.mock(fn
|
||||||
|
%{method: :post, url: "http://libre.translate/translate"} ->
|
||||||
|
%Tesla.Env{
|
||||||
|
status: 200,
|
||||||
|
body:
|
||||||
|
Jason.encode!(%{
|
||||||
|
translatedText: "I will crush you"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
end)
|
||||||
|
|
||||||
|
assert {:ok, "", "I will crush you"} =
|
||||||
|
LibreTranslate.translate("ギュギュ握りつぶしちゃうぞ", nil, "en")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue