diff options
author | Tusooa Zhu <tusooa@kazv.moe> | 2022-03-02 19:59:11 -0500 |
---|---|---|
committer | Tusooa Zhu <tusooa@kazv.moe> | 2022-03-02 19:59:11 -0500 |
commit | 8de573b04783ef50b74bd629843a58b37c0ce31d (patch) | |
tree | 1c7ad235630ef24cf8ed5cfbd8a8dbfa53aac911 /test | |
parent | 1a917cfeec3057fca9c5d1467fd9bf1401d27d42 (diff) | |
download | pleroma-8de573b04783ef50b74bd629843a58b37c0ce31d.tar.gz pleroma-8de573b04783ef50b74bd629843a58b37c0ce31d.zip |
Fallback to a variant if the language in general is not supported
For an example, here, zh is not supported, but zh_Hans and zh_Hant
are. If the user asks for zh, we should choose a variant for them
instead of fallbacking to default.
Some browsers (e.g. Firefox) does not allow users to customize
their language codes. For example, there is no zh-Hans, but only
zh, zh-CN, zh-TW, zh-HK, etc. This provides a workaround for
those users suffering from bad design decisions.
Diffstat (limited to 'test')
-rw-r--r-- | test/pleroma/web/plugs/set_locale_plug_test.exs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/test/pleroma/web/plugs/set_locale_plug_test.exs b/test/pleroma/web/plugs/set_locale_plug_test.exs index 043d7eb18..349326c24 100644 --- a/test/pleroma/web/plugs/set_locale_plug_test.exs +++ b/test/pleroma/web/plugs/set_locale_plug_test.exs @@ -47,6 +47,20 @@ defmodule Pleroma.Web.Plugs.SetLocalePlugTest do assert %{locale: "zh_Hans"} == conn.assigns end + test "fallback to some variant of the language if the unqualified language is not supported" do + conn = + :get + |> conn("/cofe") + |> Conn.put_req_header( + "accept-language", + "zh;q=0.9, en;q=0.8, *;q=0.5" + ) + |> SetLocalePlug.call([]) + + assert "zh_" <> _ = Gettext.get_locale() + assert %{locale: "zh_" <> _} = conn.assigns + end + test "use supported locale from cookie" do conn = :get |