Rename
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
066ec8fe95
commit
2b739faa7e
10 changed files with 34 additions and 31 deletions
|
|
@ -3526,38 +3526,41 @@ config :pleroma, :config_description, [
|
||||||
},
|
},
|
||||||
%{
|
%{
|
||||||
group: :pleroma,
|
group: :pleroma,
|
||||||
key: Pleroma.Translation,
|
key: Pleroma.Language.Translation,
|
||||||
type: :group,
|
type: :group,
|
||||||
description: "Translation providers",
|
description: "Translation providers",
|
||||||
children: [
|
children: [
|
||||||
%{
|
%{
|
||||||
key: :service,
|
key: :provider,
|
||||||
type: :module,
|
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,
|
key: :plan,
|
||||||
label: "DeepL plan",
|
label: "DeepL plan",
|
||||||
type: {:dropdown, :atom},
|
type: {:dropdown, :atom},
|
||||||
suggestions: [:free, :pro]
|
suggestions: [:free, :pro]
|
||||||
},
|
},
|
||||||
%{
|
%{
|
||||||
group: {:subgroup, Pleroma.Translation.Deepl},
|
group: {:subgroup, Pleroma.Language.Translation.Deepl},
|
||||||
key: :api_key,
|
key: :api_key,
|
||||||
label: "DeepL API Key",
|
label: "DeepL API Key",
|
||||||
type: :string,
|
type: :string,
|
||||||
suggestions: ["YOUR_API_KEY"]
|
suggestions: ["YOUR_API_KEY"]
|
||||||
},
|
},
|
||||||
%{
|
%{
|
||||||
group: {:subgroup, Pleroma.Translation.Libretranslate},
|
group: {:subgroup, Pleroma.Language.Translation.Libretranslate},
|
||||||
key: :base_url,
|
key: :base_url,
|
||||||
label: "LibreTranslate plan",
|
label: "LibreTranslate plan",
|
||||||
type: :string,
|
type: :string,
|
||||||
suggestions: ["https://libretranslate.com"]
|
suggestions: ["https://libretranslate.com"]
|
||||||
},
|
},
|
||||||
%{
|
%{
|
||||||
group: {:subgroup, Pleroma.Translation.Libretranslate},
|
group: {:subgroup, Pleroma.Language.Translation.Libretranslate},
|
||||||
key: :api_key,
|
key: :api_key,
|
||||||
label: "LibreTranslate API Key",
|
label: "LibreTranslate API Key",
|
||||||
type: :string,
|
type: :string,
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Translation do
|
defmodule Pleroma.Language.Translation do
|
||||||
@cachex Pleroma.Config.get([:cachex, :provider], Cachex)
|
@cachex Pleroma.Config.get([:cachex, :provider], Cachex)
|
||||||
|
|
||||||
def configured? do
|
def configured? do
|
||||||
|
|
@ -37,7 +37,7 @@ defmodule Pleroma.Translation do
|
||||||
end
|
end
|
||||||
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
|
defp get_cache_key(text, source_language, target_language) do
|
||||||
"#{source_language}/#{target_language}/#{content_hash(text)}"
|
"#{source_language}/#{target_language}/#{content_hash(text)}"
|
||||||
|
|
@ -2,19 +2,19 @@
|
||||||
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# 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]
|
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
|
def configured? do
|
||||||
not_empty_string(get_plan()) and not_empty_string(get_api_key())
|
not_empty_string(get_plan()) and not_empty_string(get_api_key())
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl Service
|
@impl Provider
|
||||||
def translate(content, source_language, target_language) do
|
def translate(content, source_language, target_language) do
|
||||||
endpoint = endpoint_url()
|
endpoint = endpoint_url()
|
||||||
|
|
||||||
|
|
@ -2,17 +2,17 @@
|
||||||
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# 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]
|
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())
|
def configured?, do: not_empty_string(get_base_url())
|
||||||
|
|
||||||
@impl Service
|
@impl Provider
|
||||||
def translate(content, source_language, target_language) do
|
def translate(content, source_language, target_language) do
|
||||||
endpoint = endpoint_url()
|
endpoint = endpoint_url()
|
||||||
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Translation.Service do
|
defmodule Pleroma.Language.Translation.Provider do
|
||||||
@callback configured?() :: boolean()
|
@callback configured?() :: boolean()
|
||||||
|
|
||||||
@callback translate(
|
@callback translate(
|
||||||
|
|
@ -12,10 +12,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do
|
||||||
|
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Bookmark
|
alias Pleroma.Bookmark
|
||||||
|
alias Pleroma.Language.Translation
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.ScheduledActivity
|
alias Pleroma.ScheduledActivity
|
||||||
alias Pleroma.Translation
|
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.ActivityPub.Visibility
|
alias Pleroma.Web.ActivityPub.Visibility
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|
||||||
end,
|
end,
|
||||||
"pleroma:get:main/ostatus",
|
"pleroma:get:main/ostatus",
|
||||||
"pleroma:group_actors",
|
"pleroma:group_actors",
|
||||||
if Pleroma.Translation.configured?() do
|
if Pleroma.Language.Translation.configured?() do
|
||||||
"translation"
|
"translation"
|
||||||
end
|
end
|
||||||
]
|
]
|
||||||
|
|
@ -206,7 +206,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|
||||||
vapid: %{
|
vapid: %{
|
||||||
public_key: Keyword.get(Pleroma.Web.Push.vapid_config(), :public_key)
|
public_key: Keyword.get(Pleroma.Web.Push.vapid_config(), :public_key)
|
||||||
},
|
},
|
||||||
translation: %{enabled: Pleroma.Translation.configured?()}
|
translation: %{enabled: Pleroma.Language.Translation.configured?()}
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
defmodule Pleroma.TranslationTest do
|
defmodule Pleroma.Language.TranslationTest do
|
||||||
use Pleroma.Web.ConnCase
|
use Pleroma.Web.ConnCase
|
||||||
|
|
||||||
alias Pleroma.Translation
|
alias Pleroma.Language.Translation
|
||||||
# use Oban.Testing, repo: Pleroma.Repo
|
# 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
|
test "it translates text" do
|
||||||
assert {:ok,
|
assert {:ok,
|
||||||
|
|
@ -2552,7 +2552,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "translating statuses" do
|
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
|
test "it translates a status to user language" do
|
||||||
user = insert(:user, language: "fr")
|
user = insert(:user, language: "fr")
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,14 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule TranslationMock do
|
defmodule TranslationMock do
|
||||||
alias Pleroma.Translation.Service
|
alias Pleroma.Language.Translation.Provider
|
||||||
|
|
||||||
@behaviour Service
|
@behaviour Provider
|
||||||
|
|
||||||
@impl Service
|
@impl Provider
|
||||||
def configured?, do: true
|
def configured?, do: true
|
||||||
|
|
||||||
@impl Service
|
@impl Provider
|
||||||
def translate(content, source_language, _target_language) do
|
def translate(content, source_language, _target_language) do
|
||||||
{:ok,
|
{:ok,
|
||||||
%{
|
%{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue