Render multilang in polls
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
6b20df1e2d
commit
e11d4b6923
3 changed files with 35 additions and 5 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.ApiSpec.Schemas.Poll do
|
defmodule Pleroma.Web.ApiSpec.Schemas.Poll do
|
||||||
alias OpenApiSpex.Schema
|
alias OpenApiSpex.Schema
|
||||||
|
alias Pleroma.Web.ApiSpec.Helpers
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.Emoji
|
alias Pleroma.Web.ApiSpec.Schemas.Emoji
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.FlakeID
|
alias Pleroma.Web.ApiSpec.Schemas.FlakeID
|
||||||
|
|
||||||
|
@ -52,6 +53,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Poll do
|
||||||
type: :object,
|
type: :object,
|
||||||
properties: %{
|
properties: %{
|
||||||
title: %Schema{type: :string},
|
title: %Schema{type: :string},
|
||||||
|
title_map: Helpers.multilang_map_of(%Schema{type: :string}),
|
||||||
votes_count: %Schema{type: :integer}
|
votes_count: %Schema{type: :integer}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -81,10 +83,12 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Poll do
|
||||||
options: [
|
options: [
|
||||||
%{
|
%{
|
||||||
title: "accept",
|
title: "accept",
|
||||||
|
title_map: %{"en" => "accept", "cmn" => "接受"},
|
||||||
votes_count: 6
|
votes_count: 6
|
||||||
},
|
},
|
||||||
%{
|
%{
|
||||||
title: "deny",
|
title: "deny",
|
||||||
|
title_map: %{"en" => "deny", "cmn" => "拒绝"},
|
||||||
votes_count: 4
|
votes_count: 4
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
|
@ -65,7 +65,8 @@ defp options_and_votes_count(options) do
|
||||||
current_count = option["replies"]["totalItems"] || 0
|
current_count = option["replies"]["totalItems"] || 0
|
||||||
|
|
||||||
{%{
|
{%{
|
||||||
title: name,
|
title: option["nameRendered"] || name,
|
||||||
|
title_map: option["nameMap"] || %{},
|
||||||
votes_count: current_count
|
votes_count: current_count
|
||||||
}, current_count + count}
|
}, current_count + count}
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -37,10 +37,10 @@ test "renders a poll" do
|
||||||
id: to_string(object.id),
|
id: to_string(object.id),
|
||||||
multiple: false,
|
multiple: false,
|
||||||
options: [
|
options: [
|
||||||
%{title: "absolutely!", votes_count: 0},
|
%{title: "absolutely!", title_map: %{}, votes_count: 0},
|
||||||
%{title: "sure", votes_count: 0},
|
%{title: "sure", title_map: %{}, votes_count: 0},
|
||||||
%{title: "yes", votes_count: 0},
|
%{title: "yes", title_map: %{}, votes_count: 0},
|
||||||
%{title: "why are you even asking?", votes_count: 0}
|
%{title: "why are you even asking?", title_map: %{}, votes_count: 0}
|
||||||
],
|
],
|
||||||
votes_count: 0,
|
votes_count: 0,
|
||||||
voters_count: 0,
|
voters_count: 0,
|
||||||
|
@ -167,6 +167,31 @@ test "doesn't strips HTML tags" do
|
||||||
} = PollView.render("show.json", %{object: object})
|
} = PollView.render("show.json", %{object: object})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "multilang" do
|
||||||
|
test "renders multilang" do
|
||||||
|
object = %Object{
|
||||||
|
id: 123,
|
||||||
|
data: %{
|
||||||
|
"oneOf" => [
|
||||||
|
%{
|
||||||
|
"name" => "mew",
|
||||||
|
"nameMap" => %{"en" => "mew", "cmn" => "喵"},
|
||||||
|
"nameRendered" => "mew | 喵"
|
||||||
|
},
|
||||||
|
%{"name" => "mew mew", "nameMap" => %{"en" => "mew mew", "cmn" => "喵喵"}}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert %{
|
||||||
|
options: [
|
||||||
|
%{title: "mew | 喵", title_map: %{"en" => "mew", "cmn" => "喵"}},
|
||||||
|
%{title: "mew mew", title_map: %{"en" => "mew mew", "cmn" => "喵喵"}}
|
||||||
|
]
|
||||||
|
} = PollView.render("show.json", %{object: object})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "displays correct voters count" do
|
test "displays correct voters count" do
|
||||||
object = Object.normalize("https://friends.grishka.me/posts/54642", fetch: true)
|
object = Object.normalize("https://friends.grishka.me/posts/54642", fetch: true)
|
||||||
result = PollView.render("show.json", %{object: object})
|
result = PollView.render("show.json", %{object: object})
|
||||||
|
|
Loading…
Reference in a new issue