1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-23 00:14:48 +00:00
mobilizon/lib/service/activity/renderer/post.ex
Thomas Citharel a670a7d7a7
Fix and improve language handling
- Refactor plugs to detect and set language
- Translate ecto validation errors
- Use Gettext directly, not Mobilizon.Web.Gettext
- Set the language in the <html> attribute according to the one loaded
  on front-end

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2021-07-27 20:11:56 +02:00

66 lines
1.6 KiB
Elixir

defmodule Mobilizon.Service.Activity.Renderer.Post do
@moduledoc """
Insert a comment activity
"""
alias Mobilizon.Activities.Activity
alias Mobilizon.Actors.Actor
alias Mobilizon.Service.Activity.Renderer
alias Mobilizon.Web.Endpoint
alias Mobilizon.Web.Router.Helpers, as: Routes
import Mobilizon.Web.Gettext, only: [dgettext: 3]
@behaviour Renderer
@impl Renderer
def render(%Activity{} = activity, options) do
locale = Keyword.get(options, :locale, "en")
Gettext.put_locale(locale)
%{
body:
text(activity.subject, %{
profile: profile(activity),
post: title(activity),
group: group(activity)
}),
url: if(activity.subject !== :post_deleted, do: post_url(activity), else: nil)
}
end
defp text(:post_created, args) do
dgettext(
"activity",
"The post %{post} from group %{group} was published by %{profile}.",
args
)
end
defp text(:post_updated, args) do
dgettext(
"activity",
"The post %{post} from group %{group} was updated by %{profile}.",
args
)
end
defp text(:post_deleted, args) do
dgettext(
"activity",
"The post %{post} from group %{group} was deleted by %{profile}.",
args
)
end
defp post_url(activity) do
Endpoint
|> Routes.page_url(
:post,
activity.subject_params["post_slug"]
)
|> URI.decode()
end
defp profile(activity), do: Actor.display_name_and_username(activity.author)
defp title(activity), do: activity.subject_params["post_title"]
defp group(activity), do: Actor.display_name_and_username(activity.group)
end