add documentation and extra tests
ci/woodpecker/push/woodpecker Pipeline is pending
Details
ci/woodpecker/push/woodpecker Pipeline is pending
Details
This commit is contained in:
parent
7fec63688c
commit
cf774bf64d
|
@ -1159,3 +1159,28 @@ Each job has these settings:
|
||||||
|
|
||||||
* `:max_running` - max concurrently runnings jobs
|
* `:max_running` - max concurrently runnings jobs
|
||||||
* `:max_waiting` - max waiting jobs
|
* `:max_waiting` - max waiting jobs
|
||||||
|
|
||||||
|
### Translation Settings
|
||||||
|
|
||||||
|
Settings to automatically translate statuses for end users. Currently supported
|
||||||
|
translation services are DeepL and LibreTranslate.
|
||||||
|
|
||||||
|
Translations are available at `/api/v1/statuses/:id/translations/:language`, where
|
||||||
|
`language` is the target language code (e.g `en`)
|
||||||
|
|
||||||
|
### `:translator`
|
||||||
|
|
||||||
|
- `:enabled` - enables translation
|
||||||
|
- `:module` - Sets module to be used
|
||||||
|
- Either `Pleroma.Akkoma.Translators.DeepL` or `Pleroma.Akkoma.Translators.LibreTranslate`
|
||||||
|
|
||||||
|
### `:deepl`
|
||||||
|
|
||||||
|
- `:api_key` - API key for DeepL
|
||||||
|
- `:tier` - API tier
|
||||||
|
- either `:free` or `:pro`
|
||||||
|
|
||||||
|
### `:libre_translate`
|
||||||
|
|
||||||
|
- `:url` - URL of LibreTranslate instance
|
||||||
|
- `:api_key` - API key for LibreTranslate
|
|
@ -30,9 +30,9 @@ defmodule Pleroma.Akkoma.Translators.DeepL do
|
||||||
|
|
||||||
{:ok, detected, translated}
|
{:ok, detected, translated}
|
||||||
else
|
else
|
||||||
{:ok, %{status: 403} = response} ->
|
{:ok, %{status: status} = response} ->
|
||||||
Logger.warning("DeepL: Request rejected, please check your API key: #{inspect(response)}")
|
Logger.warning("DeepL: Request rejected: #{inspect(response)}")
|
||||||
{:error, "DeepL request failed"}
|
{:error, "DeepL request failed (code #{status})"}
|
||||||
|
|
||||||
{:error, reason} ->
|
{:error, reason} ->
|
||||||
{:error, reason}
|
{:error, reason}
|
||||||
|
|
|
@ -21,9 +21,9 @@ defmodule Pleroma.Akkoma.Translators.LibreTranslate do
|
||||||
|
|
||||||
{:ok, detected, translated}
|
{:ok, detected, translated}
|
||||||
else
|
else
|
||||||
{:ok, %{status: 403} = response} ->
|
{:ok, %{status: status} = response} ->
|
||||||
Logger.warning("DeepL: Request rejected, please check your API key: #{inspect(response)}")
|
Logger.warning("libre_translate: request failed, #{inspect(response)}")
|
||||||
{:error, "libre_translate: request failed"}
|
{:error, "libre_translate: request failed (code #{status})"}
|
||||||
|
|
||||||
{:error, reason} ->
|
{:error, reason} ->
|
||||||
{:error, reason}
|
{:error, reason}
|
||||||
|
|
|
@ -69,7 +69,7 @@ defmodule Pleroma.Akkoma.Translators.DeepLTest do
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
assert {:error, "DeepL request failed"} = DeepL.translate("ギュギュ握りつぶしちゃうぞ", "en")
|
assert {:error, "DeepL request failed (code 403)"} = DeepL.translate("ギュギュ握りつぶしちゃうぞ", "en")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -66,8 +66,26 @@ defmodule Pleroma.Akkoma.Translators.LibreTranslateTest do
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
assert {:error, "libre_translate: request failed"} =
|
assert {:error, "libre_translate: request failed (code 403)"} =
|
||||||
LibreTranslate.translate("ギュギュ握りつぶしちゃうぞ", "en")
|
LibreTranslate.translate("ギュギュ握りつぶしちゃうぞ", "en")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "should gracefully handle an unsupported language" do
|
||||||
|
clear_config([:libre_translate, :api_key], "")
|
||||||
|
|
||||||
|
Tesla.Mock.mock(fn
|
||||||
|
%{method: :post, url: "http://libre.translate/translate"} ->
|
||||||
|
%Tesla.Env{
|
||||||
|
status: 400,
|
||||||
|
body:
|
||||||
|
Jason.encode!(%{
|
||||||
|
error: "zoop is not supported"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
end)
|
||||||
|
|
||||||
|
assert {:error, "libre_translate: request failed (code 400)"} =
|
||||||
|
LibreTranslate.translate("ギュギュ握りつぶしちゃうぞ", "zoop")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue