Navigation Menu

Skip to content

Commit

Permalink
feature #31350 [Intl] Rename Regions to Countries (ro0NL)
Browse files Browse the repository at this point in the history
This PR was merged into the 4.3-dev branch.

Discussion
----------

[Intl] Rename Regions to Countries

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no
| Tests pass?   | yes  (including intl-data group)
| Fixed tickets | #...   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

Because that's what the current region data is about; country codes.

This makes things consistent across the board; i.e. CountryType, CountryValidator

This allows a possible other region subset (e.g "continents") to distinct. Thus having `Countries::class` + `Continents::class` both reading from the `region` data. By then data should be compiled under different keys.

Current class is master only, so now or never :)

The alternative approach would be `Regions::getCountryNames [,getContinentNames, etc.]`, which is harder to scale, and should also be decided for 4.3 ideally.

Commits
-------

49aee67 [Intl] Rename Regions to Countries
  • Loading branch information
fabpot committed May 6, 2019
2 parents aa37157 + 49aee67 commit b187261
Show file tree
Hide file tree
Showing 17 changed files with 60 additions and 65 deletions.
2 changes: 1 addition & 1 deletion UPGRADE-4.3.md
Expand Up @@ -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
---------
Expand Down
2 changes: 1 addition & 1 deletion UPGRADE-5.0.md
Expand Up @@ -246,7 +246,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
---------
Expand Down
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Intl/CHANGELOG.md
Expand Up @@ -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
Expand Down
Expand Up @@ -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) {
Expand All @@ -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);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Intl/Intl.php
Expand Up @@ -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(
Expand Down
Expand Up @@ -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',
Expand Down Expand Up @@ -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());
}

/**
Expand All @@ -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));
}
}

Expand All @@ -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');
Expand All @@ -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'));
}
}
7 changes: 3 additions & 4 deletions src/Symfony/Component/Intl/Tests/CurrenciesTest.php
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Intl\Tests;

use Symfony\Component\Intl\Currencies;
use Symfony\Component\Intl\Locale;

/**
* @group intl-data
Expand Down Expand Up @@ -585,7 +584,7 @@ class CurrenciesTest extends ResourceBundleTestCase
'USS' => 998,
];

public function testGetCurrencies()
public function testGetCurrencyCodes()
{
$this->assertSame(self::$currencies, Currencies::getCurrencyCodes());
}
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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 = [];
Expand Down
7 changes: 3 additions & 4 deletions src/Symfony/Component/Intl/Tests/LanguagesTest.php
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Intl\Tests;

use Symfony\Component\Intl\Languages;
use Symfony\Component\Intl\Locale;

/**
* @group intl-data
Expand Down Expand Up @@ -824,7 +823,7 @@ class LanguagesTest extends ResourceBundleTestCase
'zu' => 'zul',
];

public function testGetLanguages()
public function testGetLanguageCodes()
{
$this->assertEquals(self::$languages, Languages::getLanguageCodes());
}
Expand All @@ -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());
}
Expand Down Expand Up @@ -874,7 +873,7 @@ public function testGetName($displayLocale)

public function testGetNameDefaultLocale()
{
Locale::setDefault('de_AT');
\Locale::setDefault('de_AT');

$names = Languages::getNames('de_AT');

Expand Down
7 changes: 3 additions & 4 deletions src/Symfony/Component/Intl/Tests/LocalesTest.php
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Component\Intl\Tests;

use Symfony\Component\Intl\Locale;
use Symfony\Component\Intl\Locales;

/**
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand Down Expand Up @@ -76,7 +75,7 @@ public function testGetName($displayLocale)

public function testGetNameDefaultLocale()
{
Locale::setDefault('de_AT');
\Locale::setDefault('de_AT');

$names = Locales::getNames('de_AT');

Expand Down
7 changes: 3 additions & 4 deletions src/Symfony/Component/Intl/Tests/ScriptsTest.php
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Component\Intl\Tests;

use Symfony\Component\Intl\Locale;
use Symfony\Component\Intl\Scripts;

/**
Expand Down Expand Up @@ -214,7 +213,7 @@ class ScriptsTest extends ResourceBundleTestCase
'Zzzz',
];

public function testGetScripts()
public function testGetScriptCodes()
{
$this->assertSame(self::$scripts, Scripts::getScriptCodes());
}
Expand All @@ -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());
}
Expand Down Expand Up @@ -266,7 +265,7 @@ public function testGetName($displayLocale)

public function testGetNameDefaultLocale()
{
Locale::setDefault('de_AT');
\Locale::setDefault('de_AT');

$names = Scripts::getNames('de_AT');

Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Intl/Tests/TimezonesTest.php
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -468,7 +468,7 @@ class TimezonesTest extends ResourceBundleTestCase
'Etc/UTC',
];

public function testGetTimezones()
public function testGetIds()
{
$this->assertEquals(self::$zones, Timezones::getIds());
}
Expand Down Expand Up @@ -652,6 +652,6 @@ public function provideCountries(): iterable
{
return array_map(function ($country) {
return [$country];
}, Regions::getRegionCodes());
}, Countries::getCountryCodes());
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Intl/Timezones.php
Expand Up @@ -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 [];
}

Expand Down

0 comments on commit b187261

Please sign in to comment.