1616
1717final class PoFileDumperTest extends TestCase
1818{
19- public function testFormatCatalog (): void
19+ public function testFormatCatalogDa (): void
2020 {
2121 $ resource = __DIR__ .'/resources/ ' ;
2222 $ locale = 'da ' ;
@@ -25,34 +25,78 @@ public function testFormatCatalog(): void
2525 $ messages = new MessageCatalogue ($ locale );
2626 $ extractor ->extract ($ resource , $ messages );
2727
28- $ outputPath = tempnam (sys_get_temp_dir (), 'po_ ' );
2928 $ dumper = new PoFileDumper ();
3029 $ output = $ dumper ->formatCatalogue ($ messages , '' , [
31- 'path ' => dirname ($ outputPath ),
32- 'output_name ' => basename ($ outputPath ),
3330 'project_name ' => 'testFormatCatalog ' ,
3431 ]);
3532
3633 $ strings = [
37- '"Plural-Forms: nplurals=2; plural=(n != 1);\n" ' ,
38- '"Language: da\n" ' ,
39- join ("\n" , [
34+ $ this ->line ('# Danish translation of testFormatCatalog ' ),
35+ $ this ->line ('"Plural-Forms: nplurals=2; plural=(n != 1);\n" ' ),
36+ $ this ->line ('"Language: da\n" ' ),
37+ $ this ->block ([
4038 'msgctxt "the context" ' ,
4139 'msgid "t filter with options context" ' ,
4240 'msgstr "t filter with options context" ' ,
4341 ]),
44- join ( "\n" , [
42+ $ this -> block ( [
4543 'msgid "Hello star." ' ,
4644 'msgid_plural "Hello @count stars." ' ,
47- 'msgstr[0] "Hello star. " ' ,
48- 'msgstr[1] "Hello @count stars. " ' ,
45+ 'msgstr[0] "@todo 0 " ' ,
46+ 'msgstr[1] "@todo 1 " ' ,
4947 ]),
5048 ];
5149 foreach ($ strings as $ string ) {
5250 $ this ->assertStringContainsString ($ string , $ output );
5351 }
5452 }
5553
54+ public function testFormatCatalogPl (): void
55+ {
56+ $ resource = __DIR__ .'/resources/ ' ;
57+ $ locale = 'pl ' ;
58+
59+ $ extractor = new TwigExtractor ($ this ->twig ());
60+ $ messages = new MessageCatalogue ($ locale );
61+ $ extractor ->extract ($ resource , $ messages );
62+
63+ $ dumper = new PoFileDumper ();
64+ $ output = $ dumper ->formatCatalogue ($ messages , '' , [
65+ 'project_name ' => 'testFormatCatalog ' ,
66+ ]);
67+
68+ $ strings = [
69+ $ this ->line ('# Polish translation of testFormatCatalog ' ),
70+ $ this ->line ('"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" ' ),
71+ $ this ->line ('"Language: pl\n" ' ),
72+ $ this ->block ([
73+ 'msgctxt "the context" ' ,
74+ 'msgid "t filter with options context" ' ,
75+ 'msgstr "t filter with options context" ' ,
76+ ]),
77+ $ this ->block ([
78+ 'msgid "Hello star." ' ,
79+ 'msgid_plural "Hello @count stars." ' ,
80+ 'msgstr[0] "@todo 0" ' ,
81+ 'msgstr[1] "@todo 1" ' ,
82+ 'msgstr[2] "@todo 2" ' ,
83+ ]),
84+ ];
85+ foreach ($ strings as $ string ) {
86+ $ this ->assertStringContainsString ($ string , $ output );
87+ }
88+ }
89+
90+ private function line (string $ string ): string
91+ {
92+ return $ string ."\n" ;
93+ }
94+
95+ private function block (array $ strings ): string
96+ {
97+ return implode ('' , array_map ($ this ->line (...), $ strings ))."\n" ;
98+ }
99+
56100 private function twig (): Environment
57101 {
58102 $ twig = new Environment (new FilesystemLoader ());
0 commit comments