Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically show English website for if browser is English #1659

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/sign_dict_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ defmodule SignDictWeb.Endpoint do
read_timeout: 60_000
)

plug(Plug.Accepts)
plug(Plug.MethodOverride)
plug(Plug.Head)

Expand Down
11 changes: 9 additions & 2 deletions lib/sign_dict_web/plugs/locale.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ defmodule SignDictWeb.Plug.Locale do
end

defp get_user_locale(conn) do
if conn.assigns[:current_user] do
conn.assigns[:current_user].locale
accept_language = Plug.Conn.get_req_header(conn, "accept-language") |> Plug.Conn.get_accept_language()

case accept_language do
[locale | _rest] ->
locale
[] when conn.assigns[:current_user] ->
conn.assigns[:current_user].locale
_ ->
nil
end
end

Expand Down