]>
Commit | Line | Data |
---|---|---|
12266213 A |
1 | <?php |
2 | ||
3 | ||
4 | namespace Shaarli; | |
5 | ||
12266213 A |
6 | use Shaarli\Config\ConfigManager; |
7 | ||
8 | /** | |
9 | * Class LanguagesFrTest | |
10 | * | |
11 | * Test the translation system in PHP and gettext mode with French language. | |
12 | * | |
13 | * @package Shaarli | |
14 | */ | |
a5a9cf23 | 15 | class LanguagesFrTest extends \Shaarli\TestCase |
12266213 A |
16 | { |
17 | /** | |
18 | * @var string Config file path (without extension). | |
19 | */ | |
20 | protected static $configFile = 'tests/utils/config/configJson'; | |
21 | ||
22 | /** | |
23 | * @var ConfigManager | |
24 | */ | |
25 | protected $conf; | |
26 | ||
27 | /** | |
28 | * Init: force French | |
29 | */ | |
8f60e120 | 30 | protected function setUp(): void |
12266213 A |
31 | { |
32 | $this->conf = new ConfigManager(self::$configFile); | |
33 | $this->conf->set('translation.language', 'fr'); | |
34 | } | |
35 | ||
36 | /** | |
37 | * Reset the locale since gettext seems to mess with it, making it too long | |
38 | */ | |
8f60e120 | 39 | public static function tearDownAfterClass(): void |
12266213 A |
40 | { |
41 | if (! empty(getenv('UT_LOCALE'))) { | |
42 | setlocale(LC_ALL, getenv('UT_LOCALE')); | |
43 | } | |
44 | } | |
45 | ||
46 | /** | |
47 | * Test t() with a simple non identified value. | |
48 | */ | |
49 | public function testTranslateSingleNotIDGettext() | |
50 | { | |
51 | $this->conf->set('translation.mode', 'gettext'); | |
52 | new Languages('en', $this->conf); | |
53 | $text = 'abcdé 564 fgK'; | |
54 | $this->assertEquals($text, t($text)); | |
55 | } | |
56 | ||
57 | /** | |
58 | * Test t() with a simple identified value in gettext mode. | |
59 | */ | |
60 | public function testTranslateSingleIDGettext() | |
61 | { | |
62 | $this->conf->set('translation.mode', 'gettext'); | |
63 | new Languages('en', $this->conf); | |
64 | $text = 'permalink'; | |
65 | $this->assertEquals('permalien', t($text)); | |
66 | } | |
67 | ||
68 | /** | |
69 | * Test t() with a non identified plural form in gettext mode. | |
70 | */ | |
71 | public function testTranslatePluralNotIDGettext() | |
72 | { | |
73 | $this->conf->set('translation.mode', 'gettext'); | |
74 | new Languages('en', $this->conf); | |
75 | $text = 'sandwich'; | |
76 | $nText = 'sandwiches'; | |
77 | // Not ID, so English fallback, and in english, plural 0 | |
78 | $this->assertEquals('sandwiches', t($text, $nText, 0)); | |
79 | $this->assertEquals('sandwich', t($text, $nText, 1)); | |
80 | $this->assertEquals('sandwiches', t($text, $nText, 2)); | |
81 | } | |
82 | ||
83 | /** | |
84 | * Test t() with an identified plural form in gettext mode. | |
85 | */ | |
86 | public function testTranslatePluralIDGettext() | |
87 | { | |
88 | $this->conf->set('translation.mode', 'gettext'); | |
89 | new Languages('en', $this->conf); | |
90 | $text = 'shaare'; | |
91 | $nText = 'shaares'; | |
92 | $this->assertEquals('shaare', t($text, $nText, 0)); | |
93 | $this->assertEquals('shaare', t($text, $nText, 1)); | |
94 | $this->assertEquals('shaares', t($text, $nText, 2)); | |
95 | } | |
96 | ||
97 | /** | |
98 | * Test t() with a simple non identified value. | |
99 | */ | |
100 | public function testTranslateSingleNotIDPhp() | |
101 | { | |
102 | $this->conf->set('translation.mode', 'php'); | |
103 | new Languages('en', $this->conf); | |
104 | $text = 'abcdé 564 fgK'; | |
105 | $this->assertEquals($text, t($text)); | |
106 | } | |
107 | ||
108 | /** | |
109 | * Test t() with a simple identified value in PHP mode. | |
110 | */ | |
111 | public function testTranslateSingleIDPhp() | |
112 | { | |
113 | $this->conf->set('translation.mode', 'php'); | |
114 | new Languages('en', $this->conf); | |
115 | $text = 'permalink'; | |
116 | $this->assertEquals('permalien', t($text)); | |
117 | } | |
118 | ||
119 | /** | |
120 | * Test t() with a non identified plural form in PHP mode. | |
121 | */ | |
122 | public function testTranslatePluralNotIDPhp() | |
123 | { | |
124 | $this->conf->set('translation.mode', 'php'); | |
125 | new Languages('en', $this->conf); | |
126 | $text = 'sandwich'; | |
127 | $nText = 'sandwiches'; | |
128 | // Not ID, so English fallback, and in english, plural 0 | |
129 | $this->assertEquals('sandwiches', t($text, $nText, 0)); | |
130 | $this->assertEquals('sandwich', t($text, $nText, 1)); | |
131 | $this->assertEquals('sandwiches', t($text, $nText, 2)); | |
132 | } | |
133 | ||
134 | /** | |
135 | * Test t() with an identified plural form in PHP mode. | |
136 | */ | |
137 | public function testTranslatePluralIDPhp() | |
138 | { | |
139 | $this->conf->set('translation.mode', 'php'); | |
140 | new Languages('en', $this->conf); | |
141 | $text = 'shaare'; | |
142 | $nText = 'shaares'; | |
143 | // In english, zero is followed by plural form | |
144 | $this->assertEquals('shaare', t($text, $nText, 0)); | |
145 | $this->assertEquals('shaare', t($text, $nText, 1)); | |
146 | $this->assertEquals('shaares', t($text, $nText, 2)); | |
147 | } | |
148 | ||
149 | /** | |
150 | * Test t() with an extension language file in gettext mode | |
151 | */ | |
152 | public function testTranslationExtensionGettext() | |
153 | { | |
154 | $this->conf->set('translation.mode', 'gettext'); | |
155 | $this->conf->set('translation.extensions.test', 'tests/utils/languages/'); | |
156 | new Languages('en', $this->conf); | |
f39580c6 A |
157 | $txt = 'car'; // ignore me poedit |
158 | $this->assertEquals('voiture', t($txt, $txt, 1, 'test')); | |
12266213 A |
159 | $this->assertEquals('Fouille', t('Search', 'Search', 1, 'test')); |
160 | } | |
161 | ||
162 | /** | |
163 | * Test t() with an extension language file in PHP mode | |
164 | */ | |
165 | public function testTranslationExtensionPhp() | |
166 | { | |
167 | $this->conf->set('translation.mode', 'php'); | |
168 | $this->conf->set('translation.extensions.test', 'tests/utils/languages/'); | |
169 | new Languages('en', $this->conf); | |
f39580c6 A |
170 | $txt = 'car'; // ignore me poedit |
171 | $this->assertEquals('voiture', t($txt, $txt, 1, 'test')); | |
12266213 A |
172 | $this->assertEquals('Fouille', t('Search', 'Search', 1, 'test')); |
173 | } | |
68c6afc5 A |
174 | |
175 | /** | |
176 | * Test t() with an extension language file coming from the theme in gettext mode | |
177 | */ | |
178 | public function testTranslationThemeExtensionGettext() | |
179 | { | |
180 | $this->conf->set('translation.mode', 'gettext'); | |
181 | $this->conf->set('raintpl_tpl', 'tests/utils/customtpl/'); | |
182 | $this->conf->set('theme', 'dummy'); | |
183 | new Languages('en', $this->conf); | |
184 | $txt = 'rooster'; // ignore me poedit | |
185 | $this->assertEquals('coq', t($txt, $txt, 1, 'dummy')); | |
186 | } | |
187 | ||
188 | /** | |
189 | * Test t() with an extension language file coming from the theme in PHP mode | |
190 | */ | |
191 | public function testTranslationThemeExtensionPhp() | |
192 | { | |
193 | $this->conf->set('translation.mode', 'php'); | |
194 | $this->conf->set('raintpl_tpl', 'tests/utils/customtpl/'); | |
195 | $this->conf->set('theme', 'dummy'); | |
196 | new Languages('en', $this->conf); | |
197 | $txt = 'rooster'; // ignore me poedit | |
198 | $this->assertEquals('coq', t($txt, $txt, 1, 'dummy')); | |
199 | } | |
12266213 | 200 | } |