add documentation and extra tests
ci/woodpecker/push/woodpecker Pipeline is pending Details

This commit is contained in:
FloatingGhost 2022-08-29 17:59:54 +01:00
parent 7fec63688c
commit cf774bf64d
5 changed files with 51 additions and 8 deletions

View File

@ -1159,3 +1159,28 @@ Each job has these settings:
* `:max_running` - max concurrently runnings 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

View File

@ -30,9 +30,9 @@ defmodule Pleroma.Akkoma.Translators.DeepL do
{:ok, detected, translated}
else
{:ok, %{status: 403} = response} ->
Logger.warning("DeepL: Request rejected, please check your API key: #{inspect(response)}")
{:error, "DeepL request failed"}
{:ok, %{status: status} = response} ->
Logger.warning("DeepL: Request rejected: #{inspect(response)}")
{:error, "DeepL request failed (code #{status})"}
{:error, reason} ->
{:error, reason}

View File

@ -21,9 +21,9 @@ defmodule Pleroma.Akkoma.Translators.LibreTranslate do
{:ok, detected, translated}
else
{:ok, %{status: 403} = response} ->
Logger.warning("DeepL: Request rejected, please check your API key: #{inspect(response)}")
{:error, "libre_translate: request failed"}
{:ok, %{status: status} = response} ->
Logger.warning("libre_translate: request failed, #{inspect(response)}")
{:error, "libre_translate: request failed (code #{status})"}
{:error, reason} ->
{:error, reason}

View File

@ -69,7 +69,7 @@ defmodule Pleroma.Akkoma.Translators.DeepLTest do
}
end)
assert {:error, "DeepL request failed"} = DeepL.translate("ギュギュ握りつぶしちゃうぞ", "en")
assert {:error, "DeepL request failed (code 403)"} = DeepL.translate("ギュギュ握りつぶしちゃうぞ", "en")
end
end
end

View File

@ -66,8 +66,26 @@ defmodule Pleroma.Akkoma.Translators.LibreTranslateTest do
}
end)
assert {:error, "libre_translate: request failed"} =
assert {:error, "libre_translate: request failed (code 403)"} =
LibreTranslate.translate("ギュギュ握りつぶしちゃうぞ", "en")
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