Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #26452 [Intl] Load locale aliases to support alias fallbacks (jak…
…zal) This PR was squashed before being merged into the 2.7 branch (closes #26452). Discussion ---------- [Intl] Load locale aliases to support alias fallbacks | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21457 | License | MIT | Doc PR | - For example, `zh_TW` is an alias to `zh_Hant_TW`. Without aliases,` zh_TW` would fall back to `zh` (which is incorrect). With aliases loaded, `zh_TW` will fall back properly to `zh_Hant_TW`. Judging by git history this has never worked. ```php \Locale::setDefault('zh'); dump(Intl::getRegionBundle()->getCountryName('AD')); \Locale::setDefault('zh_TW'); dump(Intl::getRegionBundle()->getCountryName('AD')); \Locale::setDefault('zh_Hant_TW'); dump(Intl::getRegionBundle()->getCountryName('AD')); ``` Before: ``` "安道尔" "安道尔" "安道爾" ``` After: ``` "安道尔" "安道爾" "安道爾" ``` All tests are passing, including those from the `intl-data` group. Commits ------- 1debf79 [Intl] Load locale aliases to support alias fallbacks
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Intl\Tests; | ||
|
||
use Symfony\Component\Intl\Intl; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class IntlTest extends TestCase | ||
{ | ||
/** | ||
* @requires extension intl | ||
*/ | ||
public function testIsExtensionLoadedChecksIfIntlExtensionIsLoaded() | ||
{ | ||
$this->assertTrue(Intl::isExtensionLoaded()); | ||
} | ||
|
||
public function testGetCurrencyBundleCreatesTheCurrencyBundle() | ||
{ | ||
$this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\CurrencyBundleInterface', Intl::getCurrencyBundle()); | ||
} | ||
|
||
public function testGetLanguageBundleCreatesTheLanguageBundle() | ||
{ | ||
$this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\LanguageBundleInterface', Intl::getLanguageBundle()); | ||
} | ||
|
||
public function testGetLocaleBundleCreatesTheLocaleBundle() | ||
{ | ||
$this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\LocaleBundleInterface', Intl::getLocaleBundle()); | ||
} | ||
|
||
public function testGetRegionBundleCreatesTheRegionBundle() | ||
{ | ||
$this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\LocaleBundleInterface', Intl::getLocaleBundle()); | ||
} | ||
|
||
public function testGetIcuVersionReadsTheVersionOfInstalledIcuLibrary() | ||
{ | ||
$this->assertStringMatchesFormat('%d.%d', Intl::getIcuVersion()); | ||
} | ||
|
||
public function testGetIcuDataVersionReadsTheVersionOfInstalledIcuData() | ||
{ | ||
$this->assertStringMatchesFormat('%d.%d', Intl::getIcuDataVersion()); | ||
} | ||
|
||
public function testGetIcuStubVersionReadsTheVersionOfBundledStubs() | ||
{ | ||
$this->assertStringMatchesFormat('%d.%d', Intl::getIcuStubVersion()); | ||
} | ||
|
||
public function testGetDataDirectoryReturnsThePathToIcuData() | ||
{ | ||
$this->assertTrue(is_dir(Intl::getDataDirectory())); | ||
} | ||
|
||
/** | ||
* @requires extension intl | ||
*/ | ||
public function testLocaleAliasesAreLoaded() | ||
{ | ||
\Locale::setDefault('zh_TW'); | ||
$countryNameZhTw = Intl::getRegionBundle()->getCountryName('AD'); | ||
|
||
\Locale::setDefault('zh_Hant_TW'); | ||
$countryNameHantZhTw = Intl::getRegionBundle()->getCountryName('AD'); | ||
|
||
\Locale::setDefault('zh'); | ||
$countryNameZh = Intl::getRegionBundle()->getCountryName('AD'); | ||
|
||
$this->assertSame($countryNameZhTw, $countryNameHantZhTw, 'zh_TW is an alias to zh_Hant_TW'); | ||
$this->assertNotSame($countryNameZh, $countryNameZhTw, 'zh_TW does not fall back to zh'); | ||
} | ||
} |