Skip to content
Permalink
Browse files

[Intl] Rename Regions to Countries

  • Loading branch information...
ro0NL committed May 1, 2019
1 parent c5f450b commit 49aee67f460888cf81db06a981749a610ffe6247
@@ -108,7 +108,7 @@ Intl
* Deprecated `Intl::getCurrencyBundle()`, use `Currencies` instead
* Deprecated `Intl::getLanguageBundle()`, use `Languages` or `Scripts` instead
* Deprecated `Intl::getLocaleBundle()`, use `Locales` instead
* Deprecated `Intl::getRegionBundle()`, use `Regions` instead
* Deprecated `Intl::getRegionBundle()`, use `Countries` instead

Messenger
---------
@@ -250,7 +250,7 @@ Intl
* Removed `Intl::getLanguageBundle()`, use `Languages` or `Scripts` instead
* Removed `Intl::getCurrencyBundle()`, use `Currencies` instead
* Removed `Intl::getLocaleBundle()`, use `Locales` instead
* Removed `Intl::getRegionBundle()`, use `Regions` instead
* Removed `Intl::getRegionBundle()`, use `Countries` instead

Messenger
---------
@@ -15,7 +15,7 @@
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
use Symfony\Component\Form\ChoiceList\Loader\IntlCallbackChoiceLoader;
use Symfony\Component\Intl\Regions;
use Symfony\Component\Intl\Countries;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -44,7 +44,7 @@ public function configureOptions(OptionsResolver $resolver)
$choiceTranslationLocale = $options['choice_translation_locale'];
return new IntlCallbackChoiceLoader(function () use ($choiceTranslationLocale) {
return array_flip(Regions::getNames($choiceTranslationLocale));
return array_flip(Countries::getNames($choiceTranslationLocale));
});
},
'choice_translation_domain' => false,
@@ -83,7 +83,7 @@ public function loadChoiceList($value = null)
return $this->choiceList;
}
return $this->choiceList = new ArrayChoiceList(array_flip(Regions::getNames()), $value);
return $this->choiceList = new ArrayChoiceList(array_flip(Countries::getNames()), $value);
}
/**
@@ -8,7 +8,7 @@ CHANGELOG
* added `Currencies` in favor of `Intl::getCurrencyBundle()`
* added `Languages` and `Scripts` in favor of `Intl::getLanguageBundle()`
* added `Locales` in favor of `Intl::getLocaleBundle()`
* added `Regions` in favor of `Intl::getRegionBundle()`
* added `Countries` in favor of `Intl::getRegionBundle()`
* added `Timezones`

4.2.0
@@ -19,20 +19,20 @@
* @author Bernhard Schussek <bschussek@gmail.com>
* @author Roland Franssen <franssen.roland@gmail.com>
*/
final class Regions extends ResourceBundle
final class Countries extends ResourceBundle
{
/**
* @return string[]
*/
public static function getRegionCodes(): array
public static function getCountryCodes(): array
{
return self::readEntry(['Regions'], 'meta');
}
public static function exists(string $region): bool
public static function exists(string $country): bool
{
try {
self::readEntry(['Names', $region]);
self::readEntry(['Names', $country]);
return true;
} catch (MissingResourceException $e) {
@@ -41,11 +41,11 @@ public static function exists(string $region): bool
}
/**
* @throws MissingResourceException if the region code does not exists
* @throws MissingResourceException if the country code does not exists
*/
public static function getName(string $region, string $displayLocale = null): string
public static function getName(string $country, string $displayLocale = null): string
{
return self::readEntry(['Names', $region], $displayLocale);
return self::readEntry(['Names', $country], $displayLocale);
}
/**
@@ -188,11 +188,11 @@ public static function getLocaleBundle()
*
* @return RegionBundleInterface The region resource bundle
*
* @deprecated since Symfony 4.3, to be removed in 5.0. Use {@see Regions} instead.
* @deprecated since Symfony 4.3, to be removed in 5.0. Use {@see Countries} instead.
*/
public static function getRegionBundle()
{
@trigger_error(sprintf('The method "%s()" is deprecated since Symfony 4.3, use "%s" instead.', __METHOD__, Regions::class), E_USER_DEPRECATED);
@trigger_error(sprintf('The method "%s()" is deprecated since Symfony 4.3, use "%s" instead.', __METHOD__, Countries::class), E_USER_DEPRECATED);
if (null === self::$regionBundle) {
self::$regionBundle = new RegionBundle(
@@ -11,17 +11,16 @@
namespace Symfony\Component\Intl\Tests;
use Symfony\Component\Intl\Locale;
use Symfony\Component\Intl\Regions;
use Symfony\Component\Intl\Countries;
/**
* @group intl-data
*/
class RegionsTest extends ResourceBundleTestCase
class CountriesTest extends ResourceBundleTestCase
{
// The below arrays document the state of the ICU data bundled with this package.
private static $territories = [
private static $countries = [
'AC',
'AD',
'AE',
@@ -279,28 +278,28 @@ class RegionsTest extends ResourceBundleTestCase
'ZW',
];
public function testGetRegions()
public function testGetCountryCodes()
{
$this->assertSame(self::$territories, Regions::getRegionCodes());
$this->assertSame(self::$countries, Countries::getCountryCodes());
}
/**
* @dataProvider provideLocales
*/
public function testGetNames($displayLocale)
{
$countries = array_keys(Regions::getNames($displayLocale));
$countries = array_keys(Countries::getNames($displayLocale));
sort($countries);
$this->assertSame(self::$territories, $countries);
$this->assertSame(self::$countries, $countries);
}
public function testGetNamesDefaultLocale()
{
Locale::setDefault('de_AT');
\Locale::setDefault('de_AT');
$this->assertSame(Regions::getNames('de_AT'), Regions::getNames());
$this->assertSame(Countries::getNames('de_AT'), Countries::getNames());
}
/**
@@ -311,18 +310,18 @@ public function testGetNamesSupportsAliases($alias, $ofLocale)
// Can't use assertSame(), because some aliases contain scripts with
// different collation (=order of output) than their aliased locale
// e.g. sr_Latn_ME => sr_ME
$this->assertEquals(Regions::getNames($ofLocale), Regions::getNames($alias));
$this->assertEquals(Countries::getNames($ofLocale), Countries::getNames($alias));
}
/**
* @dataProvider provideLocales
*/
public function testGetName($displayLocale)
{
$names = Regions::getNames($displayLocale);
$names = Countries::getNames($displayLocale);
foreach ($names as $country => $name) {
$this->assertSame($name, Regions::getName($country, $displayLocale));
$this->assertSame($name, Countries::getName($country, $displayLocale));
}
}
@@ -332,13 +331,13 @@ public function testGetName($displayLocale)
public function testLocaleAliasesAreLoaded()
{
\Locale::setDefault('zh_TW');
$countryNameZhTw = Regions::getName('AD');
$countryNameZhTw = Countries::getName('AD');
\Locale::setDefault('zh_Hant_TW');
$countryNameHantZhTw = Regions::getName('AD');
$countryNameHantZhTw = Countries::getName('AD');
\Locale::setDefault('zh');
$countryNameZh = Regions::getName('AD');
$countryNameZh = Countries::getName('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');
@@ -347,14 +346,14 @@ public function testLocaleAliasesAreLoaded()
/**
* @expectedException \Symfony\Component\Intl\Exception\MissingResourceException
*/
public function testGetNameWithInvalidRegionCode()
public function testGetNameWithInvalidCountryCode()
{
Regions::getName('foo');
Countries::getName('foo');
}
public function testExists()
{
$this->assertTrue(Regions::exists('NL'));
$this->assertFalse(Regions::exists('ZZ'));
$this->assertTrue(Countries::exists('NL'));
$this->assertFalse(Countries::exists('ZZ'));
}
}
@@ -12,7 +12,6 @@
namespace Symfony\Component\Intl\Tests;
use Symfony\Component\Intl\Currencies;
use Symfony\Component\Intl\Locale;
/**
* @group intl-data
@@ -585,7 +584,7 @@ class CurrenciesTest extends ResourceBundleTestCase
'USS' => 998,
];
public function testGetCurrencies()
public function testGetCurrencyCodes()
{
$this->assertSame(self::$currencies, Currencies::getCurrencyCodes());
}
@@ -613,7 +612,7 @@ public function testGetNames($displayLocale)
public function testGetNamesDefaultLocale()
{
Locale::setDefault('de_AT');
\Locale::setDefault('de_AT');
$this->assertSame(Currencies::getNames('de_AT'), Currencies::getNames());
}
@@ -646,7 +645,7 @@ public function testGetName($displayLocale)
public function testGetNameDefaultLocale()
{
Locale::setDefault('de_AT');
\Locale::setDefault('de_AT');
$expected = Currencies::getNames('de_AT');
$actual = [];
@@ -12,7 +12,6 @@
namespace Symfony\Component\Intl\Tests;
use Symfony\Component\Intl\Languages;
use Symfony\Component\Intl\Locale;
/**
* @group intl-data
@@ -824,7 +823,7 @@ class LanguagesTest extends ResourceBundleTestCase
'zu' => 'zul',
];
public function testGetLanguages()
public function testGetLanguageCodes()
{
$this->assertEquals(self::$languages, Languages::getLanguageCodes());
}
@@ -844,7 +843,7 @@ public function testGetNames($displayLocale)
public function testGetNamesDefaultLocale()
{
Locale::setDefault('de_AT');
\Locale::setDefault('de_AT');
$this->assertSame(Languages::getNames('de_AT'), Languages::getNames());
}
@@ -874,7 +873,7 @@ public function testGetName($displayLocale)
public function testGetNameDefaultLocale()
{
Locale::setDefault('de_AT');
\Locale::setDefault('de_AT');
$names = Languages::getNames('de_AT');
@@ -11,7 +11,6 @@
namespace Symfony\Component\Intl\Tests;
use Symfony\Component\Intl\Locale;
use Symfony\Component\Intl\Locales;
/**
@@ -24,7 +23,7 @@ public function testGetLocales()
$this->assertSame($this->getLocales(), Locales::getLocales());
}
public function testGetLocaleAliases()
public function testGetAliases()
{
$this->assertSame($this->getLocaleAliases(), Locales::getAliases());
}
@@ -46,7 +45,7 @@ public function testGetNames($displayLocale)
public function testGetNamesDefaultLocale()
{
Locale::setDefault('de_AT');
\Locale::setDefault('de_AT');
$this->assertSame(Locales::getNames('de_AT'), Locales::getNames());
}
@@ -76,7 +75,7 @@ public function testGetName($displayLocale)
public function testGetNameDefaultLocale()
{
Locale::setDefault('de_AT');
\Locale::setDefault('de_AT');
$names = Locales::getNames('de_AT');
@@ -11,7 +11,6 @@
namespace Symfony\Component\Intl\Tests;
use Symfony\Component\Intl\Locale;
use Symfony\Component\Intl\Scripts;
/**
@@ -214,7 +213,7 @@ class ScriptsTest extends ResourceBundleTestCase
'Zzzz',
];
public function testGetScripts()
public function testGetScriptCodes()
{
$this->assertSame(self::$scripts, Scripts::getScriptCodes());
}
@@ -236,7 +235,7 @@ public function testGetNames($displayLocale)
public function testGetNamesDefaultLocale()
{
Locale::setDefault('de_AT');
\Locale::setDefault('de_AT');
$this->assertSame(Scripts::getNames('de_AT'), Scripts::getNames());
}
@@ -266,7 +265,7 @@ public function testGetName($displayLocale)
public function testGetNameDefaultLocale()
{
Locale::setDefault('de_AT');
\Locale::setDefault('de_AT');
$names = Scripts::getNames('de_AT');
@@ -11,8 +11,8 @@
namespace Symfony\Component\Intl\Tests;
use Symfony\Component\Intl\Countries;
use Symfony\Component\Intl\Exception\MissingResourceException;
use Symfony\Component\Intl\Regions;
use Symfony\Component\Intl\Timezones;
/**
@@ -468,7 +468,7 @@ class TimezonesTest extends ResourceBundleTestCase
'Etc/UTC',
];
public function testGetTimezones()
public function testGetIds()
{
$this->assertEquals(self::$zones, Timezones::getIds());
}
@@ -652,6 +652,6 @@ public function provideCountries(): iterable
{
return array_map(function ($country) {
return [$country];
}, Regions::getRegionCodes());
}, Countries::getCountryCodes());
}
}
@@ -99,7 +99,7 @@ public static function forCountryCode(string $country): array
try {
return self::readEntry(['CountryToZone', $country], 'meta');
} catch (MissingResourceException $e) {
if (Regions::exists($country)) {
if (Countries::exists($country)) {
return [];
}
Oops, something went wrong.

0 comments on commit 49aee67

Please sign in to comment.
You can’t perform that action at this time.