From d094cdf55bcaf6becc27acce960e2ebbdba3ecbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Mon, 31 Oct 2022 21:58:10 +0100 Subject: [PATCH] Rename MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- config/description.exs | 17 ++++++++++------- lib/pleroma/{ => language}/translation.ex | 4 ++-- lib/pleroma/{ => language}/translation/deepl.ex | 10 +++++----- .../translation/libretranslate.ex | 10 +++++----- .../translation/provider.ex} | 2 +- .../controllers/status_controller.ex | 2 +- .../web/mastodon_api/views/instance_view.ex | 4 ++-- test/pleroma/{ => language}/translation_test.ex | 6 +++--- .../controllers/status_controller_test.exs | 2 +- test/support/translation_mock.ex | 8 ++++---- 10 files changed, 34 insertions(+), 31 deletions(-) rename lib/pleroma/{ => language}/translation.ex (92%) rename lib/pleroma/{ => language}/translation/deepl.ex (92%) rename lib/pleroma/{ => language}/translation/libretranslate.ex (90%) rename lib/pleroma/{translation/service.ex => language/translation/provider.ex} (92%) rename test/pleroma/{ => language}/translation_test.ex (79%) diff --git a/config/description.exs b/config/description.exs index fed4f0ac99..bf50ac1dab 100644 --- a/config/description.exs +++ b/config/description.exs @@ -3553,38 +3553,41 @@ }, %{ group: :pleroma, - key: Pleroma.Translation, + key: Pleroma.Language.Translation, type: :group, description: "Translation providers", children: [ %{ - key: :service, + key: :provider, type: :module, - suggestions: [Pleroma.Translation.Deepl, Pleroma.Translation.Libretranslate] + suggestions: [ + Pleroma.Language.Translation.Deepl, + Pleroma.Language.Translation.Libretranslate + ] }, %{ - group: {:subgroup, Pleroma.Translation.Deepl}, + group: {:subgroup, Pleroma.Language.Translation.Deepl}, key: :plan, label: "DeepL plan", type: {:dropdown, :atom}, suggestions: [:free, :pro] }, %{ - group: {:subgroup, Pleroma.Translation.Deepl}, + group: {:subgroup, Pleroma.Language.Translation.Deepl}, key: :api_key, label: "DeepL API Key", type: :string, suggestions: ["YOUR_API_KEY"] }, %{ - group: {:subgroup, Pleroma.Translation.Libretranslate}, + group: {:subgroup, Pleroma.Language.Translation.Libretranslate}, key: :base_url, label: "LibreTranslate plan", type: :string, suggestions: ["https://libretranslate.com"] }, %{ - group: {:subgroup, Pleroma.Translation.Libretranslate}, + group: {:subgroup, Pleroma.Language.Translation.Libretranslate}, key: :api_key, label: "LibreTranslate API Key", type: :string, diff --git a/lib/pleroma/translation.ex b/lib/pleroma/language/translation.ex similarity index 92% rename from lib/pleroma/translation.ex rename to lib/pleroma/language/translation.ex index 7efec62a62..c9cd9d2dd5 100644 --- a/lib/pleroma/translation.ex +++ b/lib/pleroma/language/translation.ex @@ -2,7 +2,7 @@ # Copyright © 2017-2022 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only -defmodule Pleroma.Translation do +defmodule Pleroma.Language.Translation do @cachex Pleroma.Config.get([:cachex, :provider], Cachex) def configured? do @@ -37,7 +37,7 @@ def translate(text, source_language, target_language) do end end - defp get_service, do: Pleroma.Config.get([__MODULE__, :service]) + defp get_service, do: Pleroma.Config.get([__MODULE__, :provider]) defp get_cache_key(text, source_language, target_language) do "#{source_language}/#{target_language}/#{content_hash(text)}" diff --git a/lib/pleroma/translation/deepl.ex b/lib/pleroma/language/translation/deepl.ex similarity index 92% rename from lib/pleroma/translation/deepl.ex rename to lib/pleroma/language/translation/deepl.ex index 944dab8ec8..81048378c3 100644 --- a/lib/pleroma/translation/deepl.ex +++ b/lib/pleroma/language/translation/deepl.ex @@ -2,19 +2,19 @@ # Copyright © 2017-2022 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only -defmodule Pleroma.Translation.Deepl do +defmodule Pleroma.Language.Translation.Deepl do import Pleroma.Web.Utils.Guards, only: [not_empty_string: 1] - alias Pleroma.Translation.Service + alias Pleroma.Language.Translation.Provider - @behaviour Service + @behaviour Provider - @impl Service + @impl Provider def configured? do not_empty_string(get_plan()) and not_empty_string(get_api_key()) end - @impl Service + @impl Provider def translate(content, source_language, target_language) do endpoint = endpoint_url() diff --git a/lib/pleroma/translation/libretranslate.ex b/lib/pleroma/language/translation/libretranslate.ex similarity index 90% rename from lib/pleroma/translation/libretranslate.ex rename to lib/pleroma/language/translation/libretranslate.ex index 9c9b4b9b5d..0c1fe17a04 100644 --- a/lib/pleroma/translation/libretranslate.ex +++ b/lib/pleroma/language/translation/libretranslate.ex @@ -2,17 +2,17 @@ # Copyright © 2017-2022 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only -defmodule Pleroma.Translation.Libretranslate do +defmodule Pleroma.Language.Translation.Libretranslate do import Pleroma.Web.Utils.Guards, only: [not_empty_string: 1] - alias Pleroma.Translation.Service + alias Pleroma.Language.Translation.Provider - @behaviour Service + @behaviour Provider - @impl Service + @impl Provider def configured?, do: not_empty_string(get_base_url()) - @impl Service + @impl Provider def translate(content, source_language, target_language) do endpoint = endpoint_url() diff --git a/lib/pleroma/translation/service.ex b/lib/pleroma/language/translation/provider.ex similarity index 92% rename from lib/pleroma/translation/service.ex rename to lib/pleroma/language/translation/provider.ex index 55e995e926..a88461a47f 100644 --- a/lib/pleroma/translation/service.ex +++ b/lib/pleroma/language/translation/provider.ex @@ -2,7 +2,7 @@ # Copyright © 2017-2022 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only -defmodule Pleroma.Translation.Service do +defmodule Pleroma.Language.Translation.Provider do @callback configured?() :: boolean() @callback translate( diff --git a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex index bcfdee1090..dc73cabf95 100644 --- a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex @@ -12,10 +12,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do alias Pleroma.Activity alias Pleroma.Bookmark + alias Pleroma.Language.Translation alias Pleroma.Object alias Pleroma.Repo alias Pleroma.ScheduledActivity - alias Pleroma.Translation alias Pleroma.User alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Visibility diff --git a/lib/pleroma/web/mastodon_api/views/instance_view.ex b/lib/pleroma/web/mastodon_api/views/instance_view.ex index b3c12fec9a..91ebdae3c1 100644 --- a/lib/pleroma/web/mastodon_api/views/instance_view.ex +++ b/lib/pleroma/web/mastodon_api/views/instance_view.ex @@ -143,7 +143,7 @@ def features do "profile_directory" end, "pleroma:get:main/ostatus", - if Pleroma.Translation.configured?() do + if Pleroma.Language.Translation.configured?() do "translation" end ] @@ -209,7 +209,7 @@ def configuration2 do configuration() |> Map.merge(%{ urls: %{streaming: Pleroma.Web.Endpoint.websocket_url()}, - translation: %{enabled: Pleroma.Translation.configured?()} + translation: %{enabled: Pleroma.Language.Translation.configured?()} }) end diff --git a/test/pleroma/translation_test.ex b/test/pleroma/language/translation_test.ex similarity index 79% rename from test/pleroma/translation_test.ex rename to test/pleroma/language/translation_test.ex index 2ae7856ee4..ecab3d20f7 100644 --- a/test/pleroma/translation_test.ex +++ b/test/pleroma/language/translation_test.ex @@ -1,10 +1,10 @@ -defmodule Pleroma.TranslationTest do +defmodule Pleroma.Language.TranslationTest do use Pleroma.Web.ConnCase - alias Pleroma.Translation + alias Pleroma.Language.Translation # use Oban.Testing, repo: Pleroma.Repo - setup do: clear_config([Pleroma.Translation, :service], TranslationMock) + setup do: clear_config([Pleroma.Language.Translation, :provider], TranslationMock) test "it translates text" do assert {:ok, diff --git a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs index 6d1c7befd7..d5dcaead65 100644 --- a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs @@ -2214,7 +2214,7 @@ test "it returns 404 if the user cannot see the post", %{conn: conn} do end describe "translating statuses" do - setup do: clear_config([Pleroma.Translation, :service], TranslationMock) + setup do: clear_config([Pleroma.Language.Translation, :provider], TranslationMock) test "it translates a status to user language" do user = insert(:user, language: "fr") diff --git a/test/support/translation_mock.ex b/test/support/translation_mock.ex index 8da2116e82..7e618c2639 100644 --- a/test/support/translation_mock.ex +++ b/test/support/translation_mock.ex @@ -3,14 +3,14 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule TranslationMock do - alias Pleroma.Translation.Service + alias Pleroma.Language.Translation.Provider - @behaviour Service + @behaviour Provider - @impl Service + @impl Provider def configured?, do: true - @impl Service + @impl Provider def translate(content, source_language, _target_language) do {:ok, %{