Merge 2023.05 stable #8

Merged
fedward merged 29 commits from AkkomaGang/akkoma:stable into stable 2023-05-30 19:19:23 +00:00
2 changed files with 19 additions and 3 deletions
Showing only changes of commit 3437e11cf7 - Show all commits

View file

@ -40,7 +40,7 @@ def translate(string, from_language, to_language) do
if Map.has_key?(body, "detectedLanguage") do
get_in(body, ["detectedLanguage", "language"])
else
from_language
from_language || ""
end
{:ok, detected, translated}

View file

@ -133,5 +133,21 @@ test "should gracefully handle an unsupported language" do
assert {:error, "libre_translate: request failed (code 400)"} =
LibreTranslate.translate("ギュギュ握りつぶしちゃうぞ", nil, "zoop")
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