forked from php-gettext/Gettext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoGeneratorTest.php
More file actions
119 lines (102 loc) · 3.37 KB
/
PoGeneratorTest.php
File metadata and controls
119 lines (102 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
declare(strict_types = 1);
namespace Gettext\Tests;
use Gettext\Generator\PoGenerator;
use Gettext\Translation;
use Gettext\Translations;
use PHPUnit\Framework\TestCase;
class PoGeneratorTest extends TestCase
{
public function testPoLoader()
{
$generator = new PoGenerator();
$translations = Translations::create('my-domain');
$translations->getFlags()->add('fuzzy');
$translations->setDescription(
<<<'EOT'
SOME DESCRIPTIVE TITLE
Copyright (C) YEAR Free Software Foundation, Inc.
This file is distributed under the same license as the PACKAGE package.
FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
EOT
);
$translations->setLanguage('gl_ES');
$translations->getHeaders()
->set('Content-Type', 'text/plain; charset=UTF-8')
->set('X-Generator', 'PHP-Gettext');
$translation = Translation::create('context-1', 'Original');
$translation->getComments()->add('This is a comment');
$translation->getReferences()->add('/my/template.php', 45);
$translations->add($translation);
$translation = Translation::create('context-1', 'Other comment');
$translation->translate('Outro comentario');
$translation->translatePlural('Outros comentarios');
$translation->getExtractedComments()->add('Not sure about this');
$translation->getFlags()->add('c-code');
$translations->add($translation);
$translation = Translation::create(null, 'Disabled comment');
$translation->disable();
$translation->translate('Comentario deshabilitado');
$translation->getComments()->add('This is a disabled comment');
$translations->add($translation);
// https://github.com/php-gettext/Gettext/issues/244
$translation = Translation::create(null, "foo\nbar");
$translation->translate("bar\nbaz");
$translations->add($translation);
$result = $generator->generateString($translations);
$expected = <<<'EOT'
# SOME DESCRIPTIVE TITLE
# Copyright (C) YEAR Free Software Foundation, Inc.
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Language: gl_ES\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Domain: my-domain\n"
"X-Generator: PHP-Gettext\n"
# This is a comment
#: /my/template.php:45
msgctxt "context-1"
msgid "Original"
msgstr ""
#. Not sure about this
#, c-code
msgctxt "context-1"
msgid "Other comment"
msgstr "Outro comentario"
# This is a disabled comment
#~ msgid "Disabled comment"
#~ msgstr "Comentario deshabilitado"
msgid ""
"foo\n"
"bar"
msgstr ""
"bar\n"
"baz"
EOT;
$this->assertSame($expected, $result);
}
public function stringEncodeProvider()
{
return [
['"test"', 'test'],
['"\'test\'"', "'test'"],
['"Special chars: \\n \\t \\\\ "', "Special chars: \n \t \\ "],
['"Newline\nSlash and n\\\\nend"', "Newline\nSlash and n\\nend"],
['"Quoted \\"string\\" with %s"', 'Quoted "string" with %s'],
];
}
/**
* @dataProvider stringEncodeProvider
* @param mixed $encoded
* @param mixed $decoded
*/
public function testStringEncode($encoded, $decoded)
{
$this->assertSame($encoded, PoGenerator::encode($decoded));
}
}