@@ -45,39 +45,45 @@ public function testTransWithoutCaching()
45
45
{
46
46
$ translator = $ this ->getTranslator ($ this ->getLoader ());
47
47
$ translator ->setLocale ('fr ' );
48
- $ translator ->setFallbackLocale (array ('en ' , 'es ' ));
48
+ $ translator ->setFallbackLocale (array ('en ' , 'es ' , ' pt-PT ' , ' pt_BR ' ));
49
49
50
50
$ this ->assertEquals ('foo (FR) ' , $ translator ->trans ('foo ' ));
51
51
$ this ->assertEquals ('bar (EN) ' , $ translator ->trans ('bar ' ));
52
52
$ this ->assertEquals ('foobar (ES) ' , $ translator ->trans ('foobar ' ));
53
53
$ this ->assertEquals ('choice 0 (EN) ' , $ translator ->transChoice ('choice ' , 0 ));
54
54
$ this ->assertEquals ('no translation ' , $ translator ->trans ('no translation ' ));
55
+ $ this ->assertEquals ('foobarfoo (PT-PT) ' , $ translator ->trans ('foobarfoo ' ));
56
+ $ this ->assertEquals ('other choice 1 (PT-BR) ' , $ translator ->transChoice ('other choice ' , 1 ));
55
57
}
56
58
57
59
public function testTransWithCaching ()
58
60
{
59
61
// prime the cache
60
62
$ translator = $ this ->getTranslator ($ this ->getLoader (), array ('cache_dir ' => $ this ->tmpDir ));
61
63
$ translator ->setLocale ('fr ' );
62
- $ translator ->setFallbackLocale (array ('en ' , 'es ' ));
64
+ $ translator ->setFallbackLocale (array ('en ' , 'es ' , ' pt-PT ' , ' pt_BR ' ));
63
65
64
66
$ this ->assertEquals ('foo (FR) ' , $ translator ->trans ('foo ' ));
65
67
$ this ->assertEquals ('bar (EN) ' , $ translator ->trans ('bar ' ));
66
68
$ this ->assertEquals ('foobar (ES) ' , $ translator ->trans ('foobar ' ));
67
69
$ this ->assertEquals ('choice 0 (EN) ' , $ translator ->transChoice ('choice ' , 0 ));
68
70
$ this ->assertEquals ('no translation ' , $ translator ->trans ('no translation ' ));
71
+ $ this ->assertEquals ('foobarfoo (PT-PT) ' , $ translator ->trans ('foobarfoo ' ));
72
+ $ this ->assertEquals ('other choice 1 (PT-BR) ' , $ translator ->transChoice ('other choice ' , 1 ));
69
73
70
74
// do it another time as the cache is primed now
71
75
$ loader = $ this ->getMock ('Symfony\Component\Translation\Loader\LoaderInterface ' );
72
76
$ translator = $ this ->getTranslator ($ loader , array ('cache_dir ' => $ this ->tmpDir ));
73
77
$ translator ->setLocale ('fr ' );
74
- $ translator ->setFallbackLocale (array ('en ' , 'es ' ));
78
+ $ translator ->setFallbackLocale (array ('en ' , 'es ' , ' pt-PT ' , ' pt_BR ' ));
75
79
76
80
$ this ->assertEquals ('foo (FR) ' , $ translator ->trans ('foo ' ));
77
81
$ this ->assertEquals ('bar (EN) ' , $ translator ->trans ('bar ' ));
78
82
$ this ->assertEquals ('foobar (ES) ' , $ translator ->trans ('foobar ' ));
79
83
$ this ->assertEquals ('choice 0 (EN) ' , $ translator ->transChoice ('choice ' , 0 ));
80
84
$ this ->assertEquals ('no translation ' , $ translator ->trans ('no translation ' ));
85
+ $ this ->assertEquals ('foobarfoo (PT-PT) ' , $ translator ->trans ('foobarfoo ' ));
86
+ $ this ->assertEquals ('other choice 1 (PT-BR) ' , $ translator ->transChoice ('other choice ' , 1 ));
81
87
}
82
88
83
89
public function testGetLocale ()
@@ -155,6 +161,20 @@ protected function getLoader()
155
161
'foobar ' => 'foobar (ES) ' ,
156
162
))))
157
163
;
164
+ $ loader
165
+ ->expects ($ this ->at (3 ))
166
+ ->method ('load ' )
167
+ ->will ($ this ->returnValue ($ this ->getCatalogue ('pt-PT ' , array (
168
+ 'foobarfoo ' => 'foobarfoo (PT-PT) ' ,
169
+ ))))
170
+ ;
171
+ $ loader
172
+ ->expects ($ this ->at (4 ))
173
+ ->method ('load ' )
174
+ ->will ($ this ->returnValue ($ this ->getCatalogue ('pt_BR ' , array (
175
+ 'other choice ' => '{0} other choice 0 (PT-BR)|{1} other choice 1 (PT-BR)|]1,Inf] other choice inf (PT-BR) ' ,
176
+ ))))
177
+ ;
158
178
159
179
return $ loader ;
160
180
}
@@ -183,6 +203,8 @@ public function getTranslator($loader, $options = array())
183
203
$ translator ->addResource ('loader ' , 'foo ' , 'fr ' );
184
204
$ translator ->addResource ('loader ' , 'foo ' , 'en ' );
185
205
$ translator ->addResource ('loader ' , 'foo ' , 'es ' );
206
+ $ translator ->addResource ('loader ' , 'foo ' , 'pt-PT ' ); // European Portuguese
207
+ $ translator ->addResource ('loader ' , 'foo ' , 'pt_BR ' ); // Brazilian Portuguese
186
208
187
209
return $ translator ;
188
210
}
0 commit comments