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 "duplicated locale in list should not result in infinite loops" do
42 Pleroma.Web.Gettext.with_locales ["x_unsupported", "x_unsupported", "en_test"] do
43 assert "xxYour account is awaiting approvalxx" ==
44 Pleroma.Web.Gettext.dpgettext(
46 "approval pending email subject",
47 "Your account is awaiting approval"
52 test "direct interpolation" do
53 Pleroma.Web.Gettext.with_locales ["en_test"] do
54 assert "xxYour digest from some instancexx" ==
55 Pleroma.Web.Gettext.dpgettext(
57 "digest email subject",
58 "Your digest from %{instance_name}",
59 instance_name: "some instance"
64 test "fallback with interpolation" do
65 Pleroma.Web.Gettext.with_locales ["x_unsupported", "en_test"] do
66 assert "xxYour digest from some instancexx" ==
67 Pleroma.Web.Gettext.dpgettext(
69 "digest email subject",
70 "Your digest from %{instance_name}",
71 instance_name: "some instance"
76 test "fallback to msgid" do
77 Pleroma.Web.Gettext.with_locales ["x_unsupported"] do
78 assert "Your digest from some instance" ==
79 Pleroma.Web.Gettext.dpgettext(
81 "digest email subject",
82 "Your digest from %{instance_name}",
83 instance_name: "some instance"
89 describe "handle_missing_plural_translation/7" do
90 test "direct interpolation" do
91 Pleroma.Web.Gettext.with_locales ["en_test"] do
92 assert "xx1 New Followerxx" ==
93 Pleroma.Web.Gettext.dpngettext(
95 "new followers count header",
96 "%{count} New Follower",
97 "%{count} New Followers",
102 assert "xx5 New Followersxx" ==
103 Pleroma.Web.Gettext.dpngettext(
105 "new followers count header",
106 "%{count} New Follower",
107 "%{count} New Followers",
114 test "fallback with interpolation" do
115 Pleroma.Web.Gettext.with_locales ["x_unsupported", "en_test"] do
116 assert "xx1 New Followerxx" ==
117 Pleroma.Web.Gettext.dpngettext(
119 "new followers count header",
120 "%{count} New Follower",
121 "%{count} New Followers",
126 assert "xx5 New Followersxx" ==
127 Pleroma.Web.Gettext.dpngettext(
129 "new followers count header",
130 "%{count} New Follower",
131 "%{count} New Followers",
138 test "fallback to msgid" do
139 Pleroma.Web.Gettext.with_locales ["x_unsupported"] do
140 assert "1 New Follower" ==
141 Pleroma.Web.Gettext.dpngettext(
143 "new followers count header",
144 "%{count} New Follower",
145 "%{count} New Followers",
150 assert "5 New Followers" ==
151 Pleroma.Web.Gettext.dpngettext(
153 "new followers count header",
154 "%{count} New Follower",
155 "%{count} New Followers",