Fix lang not detected on fallback pages
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
4ff936ad7a
commit
ecbc5993c4
@ -3,11 +3,12 @@ defmodule Mobilizon.Web.ErrorView do
|
|||||||
View for errors
|
View for errors
|
||||||
"""
|
"""
|
||||||
use Mobilizon.Web, :view
|
use Mobilizon.Web, :view
|
||||||
|
alias Mobilizon.Service.Metadata.Instance
|
||||||
|
alias Mobilizon.Web.PageView
|
||||||
|
|
||||||
def render("404.html", _assigns) do
|
def render("404.html", %{conn: conn}) do
|
||||||
with {:ok, index_content} <- File.read(index_file_path()) do
|
tags = Instance.build_tags()
|
||||||
{:safe, index_content}
|
PageView.inject_tags(conn, tags)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def render("404.json", _assigns) do
|
def render("404.json", _assigns) do
|
||||||
@ -48,8 +49,4 @@ defmodule Mobilizon.Web.ErrorView do
|
|||||||
Logger.warn("Template #{inspect(template)} not found")
|
Logger.warn("Template #{inspect(template)} not found")
|
||||||
render("500.html", assigns)
|
render("500.html", assigns)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp index_file_path do
|
|
||||||
Path.join(Application.app_dir(:mobilizon, "priv/static"), "index.html")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -60,7 +60,7 @@ defmodule Mobilizon.Web.PageView do
|
|||||||
end
|
end
|
||||||
|
|
||||||
@spec inject_tags(Conn.t(), List.t()) :: {:safe, String.t()}
|
@spec inject_tags(Conn.t(), List.t()) :: {:safe, String.t()}
|
||||||
defp inject_tags(conn, tags) do
|
def inject_tags(conn, tags) do
|
||||||
with {:ok, index_content} <- File.read(index_file_path()) do
|
with {:ok, index_content} <- File.read(index_file_path()) do
|
||||||
locale = get_locale(conn)
|
locale = get_locale(conn)
|
||||||
|
|
||||||
|
@ -6,9 +6,13 @@ defmodule Mobilizon.Web.ErrorViewTest do
|
|||||||
|
|
||||||
alias Mobilizon.Web.ErrorView
|
alias Mobilizon.Web.ErrorView
|
||||||
|
|
||||||
test "renders 404.html" do
|
test "renders 404.html", %{conn: conn} do
|
||||||
# Produced HTML might have new lines inside
|
# Produced HTML might have new lines inside
|
||||||
assert Regex.replace(~r/(\r\n|\n|\r) +/, render_to_string(ErrorView, "404.html", []), " ") =~
|
assert Regex.replace(
|
||||||
|
~r/(\r\n|\n|\r) +/,
|
||||||
|
render_to_string(ErrorView, "404.html", %{conn: conn}),
|
||||||
|
" "
|
||||||
|
) =~
|
||||||
"We're sorry but mobilizon doesn't work properly without JavaScript enabled. Please enable it to continue."
|
"We're sorry but mobilizon doesn't work properly without JavaScript enabled. Please enable it to continue."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user