diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 2a0605fb9e..1de8107baf 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -8,6 +8,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do """ alias Pleroma.Activity alias Pleroma.EctoType.ActivityPub.ObjectValidators + alias Pleroma.Language.LanguageDetector alias Pleroma.Maps alias Pleroma.Object alias Pleroma.Object.Containment @@ -23,6 +24,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do alias Pleroma.Workers.TransmogrifierWorker import Ecto.Query + import Pleroma.Web.CommonAPI.Utils, only: [get_valid_language: 1] import Pleroma.Web.Utils.Guards, only: [not_empty_string: 1] require Logger @@ -1100,8 +1102,9 @@ defp maybe_add_content_map(object), do: object def maybe_add_language(object) do language = - get_language_from_context(object) |> Pleroma.Web.CommonAPI.Utils.get_valid_language() || - get_language_from_content_map(object) |> Pleroma.Web.CommonAPI.Utils.get_valid_language() + get_language_from_context(object) |> get_valid_language() || + get_language_from_content_map(object) |> get_valid_language() || + get_language_from_content(object) |> get_valid_language() if language do Map.put(object, "language", language) @@ -1133,4 +1136,10 @@ defp get_language_from_content_map(%{"contentMap" => content_map, "content" => s end defp get_language_from_content_map(_), do: nil + + defp get_language_from_content(%{"summary" => summary, "content" => content}) do + LanguageDetector.detect("#{summary} #{content}") + end + + defp get_language_from_content(_), do: nil end diff --git a/test/support/language_detector_mock.ex b/test/support/language_detector_mock.ex index 2a85dcd633..3e6a258ae0 100644 --- a/test/support/language_detector_mock.ex +++ b/test/support/language_detector_mock.ex @@ -14,5 +14,5 @@ def missing_dependencies, do: [] def configured?, do: true @impl Provider - def detect(text), do: "fr" + def detect(_text), do: "fr" end