1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.GettextTest do
8 require Pleroma.Web.Gettext
10 test "put_locales/1: set the first in the list to Gettext's locale" do
11 Pleroma.Web.Gettext.put_locales(["zh_Hans", "en_test"])
13 assert "zh_Hans" == Gettext.get_locale(Pleroma.Web.Gettext)
16 test "with_locales/2: reset locale on exit" do
17 old_first_locale = Gettext.get_locale(Pleroma.Web.Gettext)
18 old_locales = Pleroma.Web.Gettext.get_locales()
20 Pleroma.Web.Gettext.with_locales ["zh_Hans", "en_test"] do
21 assert "zh_Hans" == Gettext.get_locale(Pleroma.Web.Gettext)
22 assert ["zh_Hans", "en_test"] == Pleroma.Web.Gettext.get_locales()
25 assert old_first_locale == Gettext.get_locale(Pleroma.Web.Gettext)
26 assert old_locales == Pleroma.Web.Gettext.get_locales()
29 describe "handle_missing_translation/5" do
30 test "fallback to next locale if some translation is not available" do
31 Pleroma.Web.Gettext.with_locales ["x_unsupported", "en_test"] do
32 assert "xxYour account is awaiting approvalxx" ==
33 Pleroma.Web.Gettext.dpgettext(
35 "approval pending email subject",
36 "Your account is awaiting approval"
41 test "putting en locale at the front should not make gettext fallback unexpectedly" do
42 Pleroma.Web.Gettext.with_locales ["en", "en_test"] do
43 assert "Your account is awaiting approval" ==
44 Pleroma.Web.Gettext.dpgettext(
46 "approval pending email subject",
47 "Your account is awaiting approval"
52 test "duplicated locale in list should not result in infinite loops" do
53 Pleroma.Web.Gettext.with_locales ["x_unsupported", "x_unsupported", "en_test"] do
54 assert "xxYour account is awaiting approvalxx" ==
55 Pleroma.Web.Gettext.dpgettext(
57 "approval pending email subject",
58 "Your account is awaiting approval"
63 test "direct interpolation" do
64 Pleroma.Web.Gettext.with_locales ["en_test"] do
65 assert "xxYour digest from some instancexx" ==
66 Pleroma.Web.Gettext.dpgettext(
68 "digest email subject",
69 "Your digest from %{instance_name}",
70 instance_name: "some instance"
75 test "fallback with interpolation" do
76 Pleroma.Web.Gettext.with_locales ["x_unsupported", "en_test"] do
77 assert "xxYour digest from some instancexx" ==
78 Pleroma.Web.Gettext.dpgettext(
80 "digest email subject",
81 "Your digest from %{instance_name}",
82 instance_name: "some instance"
87 test "fallback to msgid" do
88 Pleroma.Web.Gettext.with_locales ["x_unsupported"] do
89 assert "Your digest from some instance" ==
90 Pleroma.Web.Gettext.dpgettext(
92 "digest email subject",
93 "Your digest from %{instance_name}",
94 instance_name: "some instance"
100 describe "handle_missing_plural_translation/7" do
101 test "direct interpolation" do
102 Pleroma.Web.Gettext.with_locales ["en_test"] do
103 assert "xx1 New Followerxx" ==
104 Pleroma.Web.Gettext.dpngettext(
106 "new followers count header",
107 "%{count} New Follower",
108 "%{count} New Followers",
113 assert "xx5 New Followersxx" ==
114 Pleroma.Web.Gettext.dpngettext(
116 "new followers count header",
117 "%{count} New Follower",
118 "%{count} New Followers",
125 test "fallback with interpolation" do
126 Pleroma.Web.Gettext.with_locales ["x_unsupported", "en_test"] do
127 assert "xx1 New Followerxx" ==
128 Pleroma.Web.Gettext.dpngettext(
130 "new followers count header",
131 "%{count} New Follower",
132 "%{count} New Followers",
137 assert "xx5 New Followersxx" ==
138 Pleroma.Web.Gettext.dpngettext(
140 "new followers count header",
141 "%{count} New Follower",
142 "%{count} New Followers",
149 test "fallback to msgid" do
150 Pleroma.Web.Gettext.with_locales ["x_unsupported"] do
151 assert "1 New Follower" ==
152 Pleroma.Web.Gettext.dpngettext(
154 "new followers count header",
155 "%{count} New Follower",
156 "%{count} New Followers",
161 assert "5 New Followers" ==
162 Pleroma.Web.Gettext.dpngettext(
164 "new followers count header",
165 "%{count} New Follower",
166 "%{count} New Followers",