1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Efabrica\Tests; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
8
|
|
|
use Efabrica\Translatte\Translator; |
9
|
|
|
use Efabrica\Translatte\Resource\NeonDirectoryResource; |
10
|
|
|
|
11
|
|
|
class TranslatorTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
public function testLanguage(): void |
14
|
|
|
{ |
15
|
|
|
$translator = new Translator('sk_SK'); |
16
|
|
|
$translator->addResource(new NeonDirectoryResource([__DIR__ . '/translations'])); |
17
|
|
|
$this->assertSame("Akcie", $translator->translate('dictionary.app.article.actions')); |
18
|
|
|
$this->assertSame("Actions", $translator->translate('dictionary.app.article.actions', 1, [], 'en_US')); |
19
|
|
|
$this->assertSame("Actions", $translator->translate('dictionary.app.article.actions', [], 'en_US')); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testParams(): void |
23
|
|
|
{ |
24
|
|
|
$translator = new Translator('sk_SK'); |
25
|
|
|
$translator->addResource(new NeonDirectoryResource([__DIR__ . '/translations'])); |
26
|
|
|
$this->assertSame( |
27
|
|
|
"Naozaj chcete odstrániť článok <strong>Article no.1</strong>?", |
28
|
|
|
$translator->translate('dictionary.app.article.are_you_sure_you_want_to_delete_article', ['articleTitle' => 'Article no.1']) |
29
|
|
|
); |
30
|
|
|
$this->assertSame( |
31
|
|
|
"Are you sure you want to delete the article <strong>Article no.1</strong>?", |
32
|
|
|
$translator->translate('dictionary.app.article.are_you_sure_you_want_to_delete_article', 1, ['articleTitle' => 'Article no.1'], 'en_US') |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testCount(): void |
37
|
|
|
{ |
38
|
|
|
$translator = new Translator('sk_SK'); |
39
|
|
|
$translator->addResource(new NeonDirectoryResource([__DIR__ . '/translations'])); |
40
|
|
|
$this->assertSame("článok", $translator->translate('dictionary.app.article.articles_count')); |
41
|
|
|
$this->assertSame("články", $translator->translate('dictionary.app.article.articles_count', 4)); |
42
|
|
|
$this->assertSame("článkov", $translator->translate('dictionary.app.article.articles_count', 100)); |
43
|
|
|
|
44
|
|
|
$this->assertSame("article", $translator->translate('dictionary.app.article.articles_count', 1, [], 'en_US')); |
45
|
|
|
$this->assertSame("articles", $translator->translate('dictionary.app.article.articles_count', 4, [], 'en_US')); |
46
|
|
|
$this->assertSame("articles", $translator->translate('dictionary.app.article.articles_count', 99, [], 'en_US')); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testCountWithPlaceholder(): void |
50
|
|
|
{ |
51
|
|
|
$translator = new Translator('sk_SK'); |
52
|
|
|
$translator->addResource(new NeonDirectoryResource([__DIR__ . '/translations'])); |
53
|
|
|
$this->assertSame("1 článok", $translator->translate('dictionary.app.article.articles_count_with_placeholder')); |
54
|
|
|
$this->assertSame("4 články", $translator->translate('dictionary.app.article.articles_count_with_placeholder', 4)); |
55
|
|
|
$this->assertSame("100 článkov", $translator->translate('dictionary.app.article.articles_count_with_placeholder', 100)); |
56
|
|
|
$this->assertSame("4 články", $translator->translate('dictionary.app.article.articles_count_with_placeholder', ['count' => 4])); |
57
|
|
|
$this->assertSame("100 článkov", $translator->translate('dictionary.app.article.articles_count_with_placeholder', ['count' => 100])); |
58
|
|
|
|
59
|
|
|
$this->assertSame("1 article", $translator->translate('dictionary.app.article.articles_count_with_placeholder', 1, [], 'en_US')); |
60
|
|
|
$this->assertSame("4 articles", $translator->translate('dictionary.app.article.articles_count_with_placeholder', 4, [], 'en_US')); |
61
|
|
|
$this->assertSame("99 articles", $translator->translate('dictionary.app.article.articles_count_with_placeholder', 99, [], 'en_US')); |
62
|
|
|
$this->assertSame("4 articles", $translator->translate('dictionary.app.article.articles_count_with_placeholder', ['count' => 4], 'en_US')); |
63
|
|
|
$this->assertSame("99 articles", $translator->translate('dictionary.app.article.articles_count_with_placeholder', ['count' => 99], 'en_US')); |
64
|
|
|
|
65
|
|
|
// Count has higher priority for plural form as parameter count (but dont replace count parameter in params array) |
66
|
|
|
$this->assertSame("100 články", $translator->translate('dictionary.app.article.articles_count_with_placeholder', 3, ['count' => 100])); |
67
|
|
|
$this->assertSame("4 article", $translator->translate('dictionary.app.article.articles_count_with_placeholder', 1, ['count' => 4], 'en_US')); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
public function testCountSpecialFormat(): void |
72
|
|
|
{ |
73
|
|
|
$translator = new Translator('sk_SK'); |
74
|
|
|
$translator->addResource(new NeonDirectoryResource([__DIR__ . '/translations'])); |
75
|
|
|
$this->assertSame("veľký negatívny počet", $translator->translate('dictionary.app.article.count_special_format', -99)); |
76
|
|
|
$this->assertSame("negatívny počet", $translator->translate('dictionary.app.article.count_special_format', -1)); |
77
|
|
|
$this->assertSame("nula počet", $translator->translate('dictionary.app.article.count_special_format', 0)); |
78
|
|
|
$this->assertSame("jedna počet", $translator->translate('dictionary.app.article.count_special_format', 1)); |
79
|
|
|
$this->assertSame("dva,tri,štyri počet", $translator->translate('dictionary.app.article.count_special_format', 2)); |
80
|
|
|
$this->assertSame("dva,tri,štyri počet", $translator->translate('dictionary.app.article.count_special_format', 4)); |
81
|
|
|
$this->assertSame("viac ako štyri počet", $translator->translate('dictionary.app.article.count_special_format', 99)); |
82
|
|
|
|
83
|
|
|
$this->assertSame("big negative count", $translator->translate('dictionary.app.article.count_special_format', -99, [], 'en_US')); |
84
|
|
|
$this->assertSame("negative count", $translator->translate('dictionary.app.article.count_special_format', -1, [], 'en_US')); |
85
|
|
|
$this->assertSame("zero count", $translator->translate('dictionary.app.article.count_special_format', 0, [], 'en_US')); |
86
|
|
|
$this->assertSame("one count", $translator->translate('dictionary.app.article.count_special_format', 1, [], 'en_US')); |
87
|
|
|
$this->assertSame("two,three,four count", $translator->translate('dictionary.app.article.count_special_format', 2, [], 'en_US')); |
88
|
|
|
$this->assertSame("two,three,four count", $translator->translate('dictionary.app.article.count_special_format', 4, [], 'en_US')); |
89
|
|
|
$this->assertSame("more than four count", $translator->translate('dictionary.app.article.count_special_format', 99, [], 'en_US')); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testCountSpecialFormatWithPlaceholder(): void |
93
|
|
|
{ |
94
|
|
|
$translator = new Translator('sk_SK'); |
95
|
|
|
$translator->addResource(new NeonDirectoryResource([__DIR__ . '/translations'])); |
96
|
|
|
$this->assertSame("-99 - veľký negatívny počet", $translator->translate('dictionary.app.article.count_special_format_with_placeholder', -99)); |
97
|
|
|
$this->assertSame("-1 - negatívny počet", $translator->translate('dictionary.app.article.count_special_format_with_placeholder', -1)); |
98
|
|
|
$this->assertSame("0 - nula počet", $translator->translate('dictionary.app.article.count_special_format_with_placeholder', 0)); |
99
|
|
|
$this->assertSame("1 - jedna počet", $translator->translate('dictionary.app.article.count_special_format_with_placeholder', 1)); |
100
|
|
|
$this->assertSame("2 - dva,tri,štyri počet", $translator->translate('dictionary.app.article.count_special_format_with_placeholder', 2)); |
101
|
|
|
$this->assertSame("4 - dva,tri,štyri počet", $translator->translate('dictionary.app.article.count_special_format_with_placeholder', 4)); |
102
|
|
|
$this->assertSame("99 - viac ako štyri počet", $translator->translate('dictionary.app.article.count_special_format_with_placeholder', 99)); |
103
|
|
|
|
104
|
|
|
$this->assertSame("-99 - big negative count", $translator->translate('dictionary.app.article.count_special_format_with_placeholder', -99, [], 'en_US')); |
105
|
|
|
$this->assertSame("-1 - negative count", $translator->translate('dictionary.app.article.count_special_format_with_placeholder', -1, [], 'en_US')); |
106
|
|
|
$this->assertSame("0 - zero count", $translator->translate('dictionary.app.article.count_special_format_with_placeholder', 0, [], 'en_US')); |
107
|
|
|
$this->assertSame("1 - one count", $translator->translate('dictionary.app.article.count_special_format_with_placeholder', 1, [], 'en_US')); |
108
|
|
|
$this->assertSame("2 - two,three,four count", $translator->translate('dictionary.app.article.count_special_format_with_placeholder', 2, [], 'en_US')); |
109
|
|
|
$this->assertSame("4 - two,three,four count", $translator->translate('dictionary.app.article.count_special_format_with_placeholder', 4, [], 'en_US')); |
110
|
|
|
$this->assertSame("99 - more than four count", $translator->translate('dictionary.app.article.count_special_format_with_placeholder', 99, [], 'en_US')); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function testCountSpecialFormatWithParams(): void |
114
|
|
|
{ |
115
|
|
|
$translator = new Translator('sk_SK'); |
116
|
|
|
$translator->addResource(new NeonDirectoryResource([__DIR__ . '/translations'])); |
117
|
|
|
$this->assertSame("Test: -99 - veľký negatívny počet", $translator->translate('dictionary.app.article.count_special_format_with_params', -99, ['title' => 'Test'])); |
118
|
|
|
$this->assertSame("Test: -1 - negatívny počet", $translator->translate('dictionary.app.article.count_special_format_with_params', -1, ['title' => 'Test'])); |
119
|
|
|
$this->assertSame("Test: 0 - nula počet", $translator->translate('dictionary.app.article.count_special_format_with_params', 0, ['title' => 'Test'])); |
120
|
|
|
$this->assertSame("Test: 1 - jedna počet", $translator->translate('dictionary.app.article.count_special_format_with_params', 1, ['title' => 'Test'])); |
121
|
|
|
$this->assertSame("Test: 2 - dva,tri,štyri počet", $translator->translate('dictionary.app.article.count_special_format_with_params', 2, ['title' => 'Test'])); |
122
|
|
|
$this->assertSame("Test: 4 - dva,tri,štyri počet", $translator->translate('dictionary.app.article.count_special_format_with_params', 4, ['title' => 'Test'])); |
123
|
|
|
$this->assertSame("Test: 99 - viac ako štyri počet", $translator->translate('dictionary.app.article.count_special_format_with_params', 99, ['title' => 'Test'])); |
124
|
|
|
$this->assertSame("Test: -99 - veľký negatívny počet", $translator->translate('dictionary.app.article.count_special_format_with_spaces_with_params', -99, ['title' => 'Test'])); |
125
|
|
|
$this->assertSame("Test: -1 - negatívny počet", $translator->translate('dictionary.app.article.count_special_format_with_spaces_with_params', -1, ['title' => 'Test'])); |
126
|
|
|
$this->assertSame("Test: 0 - nula počet", $translator->translate('dictionary.app.article.count_special_format_with_spaces_with_params', 0, ['title' => 'Test'])); |
127
|
|
|
$this->assertSame("Test: 1 - jedna počet", $translator->translate('dictionary.app.article.count_special_format_with_spaces_with_params', 1, ['title' => 'Test'])); |
128
|
|
|
$this->assertSame("Test: 2 - dva,tri,štyri počet", $translator->translate('dictionary.app.article.count_special_format_with_spaces_with_params', 2, ['title' => 'Test'])); |
129
|
|
|
$this->assertSame("Test: 4 - dva,tri,štyri počet", $translator->translate('dictionary.app.article.count_special_format_with_spaces_with_params', 4, ['title' => 'Test'])); |
130
|
|
|
$this->assertSame("Test: 99 - viac ako štyri počet", $translator->translate('dictionary.app.article.count_special_format_with_spaces_with_params', 99, ['title' => 'Test'])); |
131
|
|
|
|
132
|
|
|
$this->assertSame("Test: -99 - big negative count", $translator->translate('dictionary.app.article.count_special_format_with_params', -99, ['title' => 'Test'], 'en_US')); |
133
|
|
|
$this->assertSame("Test: -1 - negative count", $translator->translate('dictionary.app.article.count_special_format_with_params', -1, ['title' => 'Test'], 'en_US')); |
134
|
|
|
$this->assertSame("Test: 0 - zero count", $translator->translate('dictionary.app.article.count_special_format_with_params', 0, ['title' => 'Test'], 'en_US')); |
135
|
|
|
$this->assertSame("Test: 1 - one count", $translator->translate('dictionary.app.article.count_special_format_with_params', 1, ['title' => 'Test'], 'en_US')); |
136
|
|
|
$this->assertSame("Test: 2 - two,three,four count", $translator->translate('dictionary.app.article.count_special_format_with_params', 2, ['title' => 'Test'], 'en_US')); |
137
|
|
|
$this->assertSame("Test: 4 - two,three,four count", $translator->translate('dictionary.app.article.count_special_format_with_params', 4, ['title' => 'Test'], 'en_US')); |
138
|
|
|
$this->assertSame("Test: 99 - more than four count", $translator->translate('dictionary.app.article.count_special_format_with_params', 99, ['title' => 'Test'], 'en_US')); |
139
|
|
|
$this->assertSame("Test: -99 - big negative count", $translator->translate('dictionary.app.article.count_special_format_with_spaces_with_params', -99, ['title' => 'Test'], 'en_US')); |
140
|
|
|
$this->assertSame("Test: -1 - negative count", $translator->translate('dictionary.app.article.count_special_format_with_spaces_with_params', -1, ['title' => 'Test'], 'en_US')); |
141
|
|
|
$this->assertSame("Test: 0 - zero count", $translator->translate('dictionary.app.article.count_special_format_with_spaces_with_params', 0, ['title' => 'Test'], 'en_US')); |
142
|
|
|
$this->assertSame("Test: 1 - one count", $translator->translate('dictionary.app.article.count_special_format_with_spaces_with_params', 1, ['title' => 'Test'], 'en_US')); |
143
|
|
|
$this->assertSame("Test: 2 - two,three,four count", $translator->translate('dictionary.app.article.count_special_format_with_spaces_with_params', 2, ['title' => 'Test'], 'en_US')); |
144
|
|
|
$this->assertSame("Test: 4 - two,three,four count", $translator->translate('dictionary.app.article.count_special_format_with_spaces_with_params', 4, ['title' => 'Test'], 'en_US')); |
145
|
|
|
$this->assertSame("Test: 99 - more than four count", $translator->translate('dictionary.app.article.count_special_format_with_spaces_with_params', 99, ['title' => 'Test'], 'en_US')); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function testAll(): void |
149
|
|
|
{ |
150
|
|
|
$skParams = ['category' => 'Novinky', 'section' => 'Článnky']; |
151
|
|
|
$enParams = ['category' => 'News', 'section' => 'Articles']; |
152
|
|
|
|
153
|
|
|
$translator = new Translator('sk_SK'); |
154
|
|
|
$translator->addResource(new NeonDirectoryResource([__DIR__ . '/translations'])); |
155
|
|
|
$this->assertSame("článok v kategórii Novinky a sekcii Článnky", $translator->translate('dictionary.app.article.articles_count_with_params', $skParams)); |
156
|
|
|
$this->assertSame("články v kategórii Novinky a sekcii Článnky", $translator->translate('dictionary.app.article.articles_count_with_params', 4, $skParams)); |
157
|
|
|
$this->assertSame("článkov v kategórii Novinky a sekcii Článnky", $translator->translate('dictionary.app.article.articles_count_with_params', 100, $skParams)); |
158
|
|
|
|
159
|
|
|
$this->assertSame("article in category News and section Articles", $translator->translate('dictionary.app.article.articles_count_with_params', 1, $enParams, 'en_US')); |
160
|
|
|
$this->assertSame("articles in category News and section Articles", $translator->translate('dictionary.app.article.articles_count_with_params', 4, $enParams, 'en_US')); |
161
|
|
|
$this->assertSame("articles in category News and section Articles", $translator->translate('dictionary.app.article.articles_count_with_params', 99, $enParams, 'en_US')); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths