5 use Shaarli\Config\ConfigManager
;
10 class LanguagesTest
extends \Shaarli\TestCase
13 * @var string Config file path (without extension).
15 protected static $configFile = 'tests/utils/config/configJson';
25 protected function setUp(): void
27 $this->conf
= new ConfigManager(self
::$configFile);
31 * Test t() with a simple non identified value.
33 public function testTranslateSingleNotIDGettext()
35 $this->conf
->set('translation.mode', 'gettext');
36 new Languages('en', $this->conf
);
37 $text = 'abcdé 564 fgK';
38 $this->assertEquals($text, t($text));
42 * Test t() with a simple identified value in gettext mode.
44 public function testTranslateSingleIDGettext()
46 $this->conf
->set('translation.mode', 'gettext');
47 new Languages('en', $this->conf
);
49 $this->assertEquals($text, t($text));
53 * Test t() with a non identified plural form in gettext mode.
55 public function testTranslatePluralNotIDGettext()
57 $this->conf
->set('translation.mode', 'gettext');
58 new Languages('en', $this->conf
);
60 $nText = 'sandwiches';
61 $this->assertEquals('sandwiches', t($text, $nText, 0));
62 $this->assertEquals('sandwich', t($text, $nText, 1));
63 $this->assertEquals('sandwiches', t($text, $nText, 2));
67 * Test t() with an identified plural form in gettext mode.
69 public function testTranslatePluralIDGettext()
71 $this->conf
->set('translation.mode', 'gettext');
72 new Languages('en', $this->conf
);
75 // In english, zero is followed by plural form
76 $this->assertEquals('shaares', t($text, $nText, 0));
77 $this->assertEquals('shaare', t($text, $nText, 1));
78 $this->assertEquals('shaares', t($text, $nText, 2));
82 * Test t() with a simple non identified value.
84 public function testTranslateSingleNotIDPhp()
86 $this->conf
->set('translation.mode', 'php');
87 new Languages('en', $this->conf
);
88 $text = 'abcdé 564 fgK';
89 $this->assertEquals($text, t($text));
93 * Test t() with a simple identified value in PHP mode.
95 public function testTranslateSingleIDPhp()
97 $this->conf
->set('translation.mode', 'php');
98 new Languages('en', $this->conf
);
100 $this->assertEquals($text, t($text));
104 * Test t() with a non identified plural form in PHP mode.
106 public function testTranslatePluralNotIDPhp()
108 $this->conf
->set('translation.mode', 'php');
109 new Languages('en', $this->conf
);
111 $nText = 'sandwiches';
112 $this->assertEquals('sandwiches', t($text, $nText, 0));
113 $this->assertEquals('sandwich', t($text, $nText, 1));
114 $this->assertEquals('sandwiches', t($text, $nText, 2));
118 * Test t() with an identified plural form in PHP mode.
120 public function testTranslatePluralIDPhp()
122 $this->conf
->set('translation.mode', 'php');
123 new Languages('en', $this->conf
);
126 // In english, zero is followed by plural form
127 $this->assertEquals('shaares', t($text, $nText, 0));
128 $this->assertEquals('shaare', t($text, $nText, 1));
129 $this->assertEquals('shaares', t($text, $nText, 2));
133 * Test t() with an invalid language set in the configuration in gettext mode.
135 public function testTranslateWithInvalidConfLanguageGettext()
137 $this->conf
->set('translation.mode', 'gettext');
138 $this->conf
->set('translation.language', 'nope');
139 new Languages('fr', $this->conf
);
141 $this->assertEquals($text, t($text));
145 * Test t() with an invalid language set in the configuration in PHP mode.
147 public function testTranslateWithInvalidConfLanguagePhp()
149 $this->conf
->set('translation.mode', 'php');
150 $this->conf
->set('translation.language', 'nope');
151 new Languages('fr', $this->conf
);
153 $this->assertEquals($text, t($text));
157 * Test t() with an invalid language set with auto language in gettext mode.
159 public function testTranslateWithInvalidAutoLanguageGettext()
161 $this->conf
->set('translation.mode', 'gettext');
162 new Languages('nope', $this->conf
);
164 $this->assertEquals($text, t($text));
168 * Test t() with an invalid language set with auto language in PHP mode.
170 public function testTranslateWithInvalidAutoLanguagePhp()
172 $this->conf
->set('translation.mode', 'php');
173 new Languages('nope', $this->conf
);
175 $this->assertEquals($text, t($text));
179 * Test t() with an extension language file coming from the theme in gettext mode
181 public function testTranslationThemeExtensionGettext()
183 $this->conf
->set('translation.mode', 'gettext');
184 $this->conf
->set('raintpl_tpl', 'tests/utils/customtpl/');
185 $this->conf
->set('theme', 'dummy');
186 new Languages('en', $this->conf
);
187 $txt = 'rooster'; // ignore me poedit
188 $this->assertEquals('rooster', t($txt, $txt, 1, 'dummy'));
192 * Test t() with an extension language file coming from the theme in PHP mode
194 public function testTranslationThemeExtensionPhp()
196 $this->conf
->set('translation.mode', 'php');
197 $this->conf
->set('raintpl_tpl', 'tests/utils/customtpl/');
198 $this->conf
->set('theme', 'dummy');
199 new Languages('en', $this->conf
);
200 $txt = 'rooster'; // ignore me poedit
201 $this->assertEquals('rooster', t($txt, $txt, 1, 'dummy'));
205 * Test t() with an extension language file in gettext mode
207 public function testTranslationExtensionGettext()
209 $this->conf
->set('translation.mode', 'gettext');
210 $this->conf
->set('translation.extensions.test', 'tests/utils/languages/');
211 new Languages('en', $this->conf
);
212 $txt = 'car'; // ignore me poedit
213 $this->assertEquals('car', t($txt, $txt, 1, 'test'));
214 $this->assertEquals('Search', t('Search', 'Search', 1, 'test'));
218 * Test t() with an extension language file in PHP mode
220 public function testTranslationExtensionPhp()
222 $this->conf
->set('translation.mode', 'php');
223 $this->conf
->set('translation.extensions.test', 'tests/utils/languages/');
224 new Languages('en', $this->conf
);
225 $txt = 'car'; // ignore me poedit
226 $this->assertEquals('car', t($txt, $txt, 1, 'test'));
227 $this->assertEquals('Search', t('Search', 'Search', 1, 'test'));