1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Plugs.SetLocalePlugTest do
6 use ExUnit.Case, async: true
9 alias Pleroma.Plugs.SetLocalePlug
12 test "default locale is `en`" do
16 |> SetLocalePlug.call([])
18 assert "en" == Gettext.get_locale()
19 assert %{locale: "en"} == conn.assigns
22 test "use supported locale from `accept-language`" do
26 |> Conn.put_req_header(
28 "ru, fr-CH, fr;q=0.9, en;q=0.8, *;q=0.5"
30 |> SetLocalePlug.call([])
32 assert "ru" == Gettext.get_locale()
33 assert %{locale: "ru"} == conn.assigns
36 test "use default locale if locale from `accept-language` is not supported" do
40 |> Conn.put_req_header("accept-language", "tlh")
41 |> SetLocalePlug.call([])
43 assert "en" == Gettext.get_locale()
44 assert %{locale: "en"} == conn.assigns