File tree 2 files changed +61
-0
lines changed
Filter options
src/Symfony/Component/Intl
2 files changed +61
-0
lines changed
Original file line number Diff line number Diff line change @@ -67,6 +67,21 @@ public static function getDefaultFallback()
67
67
*/
68
68
public static function getFallback ($ locale )
69
69
{
70
+ if (function_exists ('locale_parse ' )) {
71
+ $ localesSubTags = locale_parse ($ locale );
72
+ if (1 === count ($ localesSubTags )) {
73
+ if (self ::$ defaultFallback === $ localesSubTags ['language ' ]) {
74
+ return 'root ' ;
75
+ }
76
+
77
+ return self ::$ defaultFallback ;
78
+ }
79
+
80
+ array_pop ($ localesSubTags );
81
+
82
+ return locale_compose ($ localesSubTags );
83
+ }
84
+
70
85
if (false === $ pos = strrpos ($ locale , '_ ' )) {
71
86
if (self ::$ defaultFallback === $ locale ) {
72
87
return 'root ' ;
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony \Component \Intl \Tests ;
13
+
14
+ use PHPUnit \Framework \TestCase ;
15
+ use Symfony \Component \Intl \Locale ;
16
+
17
+ class LocaleTest extends TestCase
18
+ {
19
+ public function provideGetFallbackTests ()
20
+ {
21
+ $ tests = array (
22
+ array ('fr ' , 'fr_FR ' ),
23
+ array ('en ' , 'fr ' ),
24
+ array ('root ' , 'en ' ),
25
+ );
26
+
27
+ if (function_exists ('locale_parse ' )) {
28
+ $ tests [] = array ('sl_Latn_IT ' , 'sl_Latn_IT_nedis ' );
29
+ $ tests [] = array ('sl_Latn_IT ' , 'sl-Latn-IT-nedis ' );
30
+ $ tests [] = array ('sl_Latn ' , 'sl_Latn_IT ' );
31
+ $ tests [] = array ('sl_Latn ' , 'sl-Latn-IT ' );
32
+ $ tests [] = array ('sl ' , 'sl_Latn ' );
33
+ $ tests [] = array ('sl ' , 'sl-Latn ' );
34
+ }
35
+
36
+ return $ tests ;
37
+ }
38
+
39
+ /**
40
+ * @dataProvider provideGetFallbackTests
41
+ */
42
+ public function testGetFallback ($ expected , $ locale )
43
+ {
44
+ $ this ->assertSame ($ expected , Locale::getFallback ($ locale ));
45
+ }
46
+ }
You can’t perform that action at this time.
0 commit comments