diff --git a/config/description.exs b/config/description.exs index f3395863c8..f497a12ff3 100644 --- a/config/description.exs +++ b/config/description.exs @@ -3567,10 +3567,10 @@ }, %{ group: {:subgroup, Pleroma.Language.Translation.Deepl}, - key: :plan, - label: "DeepL plan", - type: {:dropdown, :atom}, - suggestions: [:free, :pro] + key: :base_url, + label: "DeepL base URL", + type: :string, + suggestions: ["https://api-free.deepl.com", "https://api.deepl.com"] }, %{ group: {:subgroup, Pleroma.Language.Translation.Deepl}, @@ -3582,7 +3582,7 @@ %{ group: {:subgroup, Pleroma.Language.Translation.Libretranslate}, key: :base_url, - label: "LibreTranslate plan", + label: "LibreTranslate instance URL", type: :string, suggestions: ["https://libretranslate.com"] }, diff --git a/lib/pleroma/language/translation/deepl.ex b/lib/pleroma/language/translation/deepl.ex index 6942f0477d..5a34740906 100644 --- a/lib/pleroma/language/translation/deepl.ex +++ b/lib/pleroma/language/translation/deepl.ex @@ -11,12 +11,12 @@ defmodule Pleroma.Language.Translation.Deepl do @impl Provider def configured? do - is_atom(get_plan()) and not_empty_string(get_api_key()) + is_atom(get_base_url()) and not_empty_string(get_api_key()) end @impl Provider def translate(content, source_language, target_language) do - endpoint = endpoint_url() + endpoint = get_base_url() case Pleroma.HTTP.post( endpoint <> @@ -58,15 +58,8 @@ def translate(content, source_language, target_language) do end end - defp endpoint_url do - case get_plan() do - :free -> "https://api-free.deepl.com/v2/translate" - _ -> "https://api.deepl.com/v2/translate" - end - end - - defp get_plan do - Pleroma.Config.get([__MODULE__, :plan]) + defp get_base_url do + Pleroma.Config.get([__MODULE__, :base_url]) end defp get_api_key do diff --git a/test/pleroma/language/translation/deepl_test.ex b/test/pleroma/language/translation/deepl_test.ex index 9acda15dab..0c29b84a4e 100644 --- a/test/pleroma/language/translation/deepl_test.ex +++ b/test/pleroma/language/translation/deepl_test.ex @@ -9,7 +9,7 @@ defmodule Pleroma.Language.Translation.DeeplTest do test "it translates text" do Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end) - clear_config([Pleroma.Language.Translation.Deepl, :plan], :free) + clear_config([Pleroma.Language.Translation.Deepl, :base_url], "https://api-free.deepl.com") clear_config([Pleroma.Language.Translation.Deepl, :api_key], "API_KEY") {:ok, res} =