Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1debf79

Browse filesBrowse files
committed
[Intl] Load locale aliases to support alias fallbacks
1 parent 1616d36 commit 1debf79
Copy full SHA for 1debf79

File tree

2 files changed

+90
-0
lines changed
Filter options

2 files changed

+90
-0
lines changed

‎src/Symfony/Component/Intl/Intl.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Intl/Intl.php
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Intl\Data\Bundle\Reader\BufferedBundleReader;
1616
use Symfony\Component\Intl\Data\Bundle\Reader\BundleEntryReader;
1717
use Symfony\Component\Intl\Data\Bundle\Reader\BundleEntryReaderInterface;
18+
use Symfony\Component\Intl\Data\Provider\LocaleDataProvider;
1819
use Symfony\Component\Intl\Data\Provider\ScriptDataProvider;
1920
use Symfony\Component\Intl\ResourceBundle\CurrencyBundle;
2021
use Symfony\Component\Intl\ResourceBundle\CurrencyBundleInterface;
@@ -259,6 +260,11 @@ private static function getEntryReader()
259260
new JsonBundleReader(),
260261
self::BUFFER_SIZE
261262
));
263+
$localeDataProvider = new LocaleDataProvider(
264+
self::getDataDirectory().'/'.self::LOCALE_DIR,
265+
self::$entryReader
266+
);
267+
self::$entryReader->setLocaleAliases($localeDataProvider->getAliases());
262268
}
263269

264270
return self::$entryReader;
+84Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 Symfony\Component\Intl\Intl;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class IntlTest extends TestCase
18+
{
19+
/**
20+
* @requires extension intl
21+
*/
22+
public function testIsExtensionLoadedChecksIfIntlExtensionIsLoaded()
23+
{
24+
$this->assertTrue(Intl::isExtensionLoaded());
25+
}
26+
27+
public function testGetCurrencyBundleCreatesTheCurrencyBundle()
28+
{
29+
$this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\CurrencyBundleInterface', Intl::getCurrencyBundle());
30+
}
31+
32+
public function testGetLanguageBundleCreatesTheLanguageBundle()
33+
{
34+
$this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\LanguageBundleInterface', Intl::getLanguageBundle());
35+
}
36+
37+
public function testGetLocaleBundleCreatesTheLocaleBundle()
38+
{
39+
$this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\LocaleBundleInterface', Intl::getLocaleBundle());
40+
}
41+
42+
public function testGetRegionBundleCreatesTheRegionBundle()
43+
{
44+
$this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\LocaleBundleInterface', Intl::getLocaleBundle());
45+
}
46+
47+
public function testGetIcuVersionReadsTheVersionOfInstalledIcuLibrary()
48+
{
49+
$this->assertStringMatchesFormat('%d.%d', Intl::getIcuVersion());
50+
}
51+
52+
public function testGetIcuDataVersionReadsTheVersionOfInstalledIcuData()
53+
{
54+
$this->assertStringMatchesFormat('%d.%d', Intl::getIcuDataVersion());
55+
}
56+
57+
public function testGetIcuStubVersionReadsTheVersionOfBundledStubs()
58+
{
59+
$this->assertStringMatchesFormat('%d.%d', Intl::getIcuStubVersion());
60+
}
61+
62+
public function testGetDataDirectoryReturnsThePathToIcuData()
63+
{
64+
$this->assertTrue(is_dir(Intl::getDataDirectory()));
65+
}
66+
67+
/**
68+
* @requires extension intl
69+
*/
70+
public function testLocaleAliasesAreLoaded()
71+
{
72+
\Locale::setDefault('zh_TW');
73+
$countryNameZhTw = Intl::getRegionBundle()->getCountryName('AD');
74+
75+
\Locale::setDefault('zh_Hant_TW');
76+
$countryNameHantZhTw = Intl::getRegionBundle()->getCountryName('AD');
77+
78+
\Locale::setDefault('zh');
79+
$countryNameZh = Intl::getRegionBundle()->getCountryName('AD');
80+
81+
$this->assertSame($countryNameZhTw, $countryNameHantZhTw, 'zh_TW is an alias to zh_Hant_TW');
82+
$this->assertNotSame($countryNameZh, $countryNameZhTw, 'zh_TW does not fall back to zh');
83+
}
84+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.