Rename
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
9cdce15a42
commit
d094cdf55b
10 changed files with 34 additions and 31 deletions
|
@ -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,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||
# 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)}"
|
|
@ -2,19 +2,19 @@
|
|||
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||
# 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()
|
||||
|
|
@ -2,17 +2,17 @@
|
|||
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||
# 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()
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Translation.Service do
|
||||
defmodule Pleroma.Language.Translation.Provider do
|
||||
@callback configured?() :: boolean()
|
||||
|
||||
@callback translate(
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
|
@ -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")
|
||||
|
|
|
@ -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,
|
||||
%{
|
||||
|
|
Loading…
Reference in a new issue