diff --git a/lib/sign_dict_web/endpoint.ex b/lib/sign_dict_web/endpoint.ex index 1e8a9fb0..81f0ed6b 100644 --- a/lib/sign_dict_web/endpoint.ex +++ b/lib/sign_dict_web/endpoint.ex @@ -51,6 +51,7 @@ defmodule SignDictWeb.Endpoint do read_timeout: 60_000 ) + plug(Plug.Accepts) plug(Plug.MethodOverride) plug(Plug.Head) diff --git a/lib/sign_dict_web/plugs/locale.ex b/lib/sign_dict_web/plugs/locale.ex index db6edb72..27100c3b 100644 --- a/lib/sign_dict_web/plugs/locale.ex +++ b/lib/sign_dict_web/plugs/locale.ex @@ -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