diff --git a/src/Symfony/Component/Intl/NumberFormatter/StubNumberFormatter.php b/src/Symfony/Component/Intl/NumberFormatter/StubNumberFormatter.php index f930d41b1e..b34ca11ad3 100644 --- a/src/Symfony/Component/Intl/NumberFormatter/StubNumberFormatter.php +++ b/src/Symfony/Component/Intl/NumberFormatter/StubNumberFormatter.php @@ -300,7 +300,7 @@ class StubNumberFormatter return $this->format($value); } - $symbol = Intl::getCurrencyBundle()->getCurrencySymbol('en', $currency); + $symbol = Intl::getCurrencyBundle()->getCurrencySymbol($currency, 'en'); $fractionDigits = Intl::getCurrencyBundle()->getFractionDigits($currency); $value = $this->roundCurrency($value, $currency); diff --git a/src/Symfony/Component/Intl/README.md b/src/Symfony/Component/Intl/README.md index 33bef34531..a14a2a0118 100644 --- a/src/Symfony/Component/Intl/README.md +++ b/src/Symfony/Component/Intl/README.md @@ -55,13 +55,13 @@ Numbers can be formatted with the [`\NumberFormatter`] [3] class. The following methods are supported. All other methods are not supported and will throw an exception when used. -##### __construct($locale = 'en', $style = null, $pattern = null) +##### __construct($locale = $style = null, $pattern = null) The only supported locale is "en". The supported styles are `\NumberFormatter::DECIMAL` and `\NumberFormatter::CURRENCY`. The argument `$pattern` may not be used. -##### ::create($locale = 'en', $style = null, $pattern = null) +##### ::create($locale = $style = null, $pattern = null) See `__construct()`. @@ -115,19 +115,19 @@ Languages and Scripts The translations of language and script names can be found in the language bundle. - $languages = Intl::getLanguageBundle()->getLanguageNames('en'); + $languages = Intl::getLanguageBundle()->getLanguageNames(); // => array('ab' => 'Abkhazian', ...) - $language = Intl::getLanguageBundle()->getLanguageName('en', 'de'); + $language = Intl::getLanguageBundle()->getLanguageName('de'); // => 'German' - $language = Intl::getLanguageBundle()->getLanguageName('en', 'de', 'AT); + $language = Intl::getLanguageBundle()->getLanguageName('de', 'AT); // => 'Austrian German' - $scripts = Intl::getLanguageBundle()->getScriptNames('en'); + $scripts = Intl::getLanguageBundle()->getScriptNames(); // => array('Arab' => 'Arabic', ...) - $script = Intl::getLanguageBundle()->getScriptName('en', 'Hans'); + $script = Intl::getLanguageBundle()->getScriptName('Hans'); // => 'Simplified' Countries @@ -135,10 +135,10 @@ Countries The translations of country names can be found in the region bundle. - $countries = Intl::getRegionBundle()->getCountryNames('en'); + $countries = Intl::getRegionBundle()->getCountryNames(); // => array('AF' => 'Afghanistan', ...) - $country = Intl::getRegionBundle()->getCountryName('en', 'GB'); + $country = Intl::getRegionBundle()->getCountryName('GB'); // => 'United Kingdom' Locales @@ -146,10 +146,10 @@ Locales The translations of locale names can be found in the locale bundle. - $locales = Intl::getLocaleBundle()->getLocaleNames('en'); + $locales = Intl::getLocaleBundle()->getLocaleNames(); // => array('af' => 'Afrikaans', ...) - $locale = Intl::getLocaleBundle()->getLocaleName('en', 'zh_Hans_MO'); + $locale = Intl::getLocaleBundle()->getLocaleName('zh_Hans_MO'); // => 'Chinese (Simplified, Macau SAR China)' Currencies @@ -158,13 +158,13 @@ Currencies The translations of currency names and other currency-related information can be found in the currency bundle. - $currencies = Intl::getCurrencyBundle()->getCurrencyNames('en'); + $currencies = Intl::getCurrencyBundle()->getCurrencyNames(); // => array('AFN' => 'Afghan Afghani', ...) - $currency = Intl::getCurrencyBundle()->getCurrencyNames('en', 'INR'); + $currency = Intl::getCurrencyBundle()->getCurrencyNames('INR'); // => 'Indian Rupee' - $symbol = Intl::getCurrencyBundle()->getCurrencyNames('en', 'INR'); + $symbol = Intl::getCurrencyBundle()->getCurrencyNames('INR'); // => '₹' $fractionDigits = Intl::getCurrencyBundle()->getFractionDigits('INR'); diff --git a/src/Symfony/Component/Intl/ResourceBundle/CurrencyBundle.php b/src/Symfony/Component/Intl/ResourceBundle/CurrencyBundle.php index c32e2c4980..6f2a0ed395 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/CurrencyBundle.php +++ b/src/Symfony/Component/Intl/ResourceBundle/CurrencyBundle.php @@ -29,24 +29,36 @@ class CurrencyBundle extends AbstractBundle implements CurrencyBundleInterface /** * {@inheritdoc} */ - public function getCurrencySymbol($locale, $currency) + public function getCurrencySymbol($currency, $locale = null) { + if (null === $locale) { + $locale = \Locale::getDefault(); + } + return $this->readEntry($locale, array('Currencies', $currency, static::INDEX_SYMBOL)); } /** * {@inheritdoc} */ - public function getCurrencyName($locale, $currency) + public function getCurrencyName($currency, $locale = null) { + if (null === $locale) { + $locale = \Locale::getDefault(); + } + return $this->readEntry($locale, array('Currencies', $currency, static::INDEX_NAME)); } /** * {@inheritdoc} */ - public function getCurrencyNames($locale) + public function getCurrencyNames($locale = null) { + if (null === $locale) { + $locale = \Locale::getDefault(); + } + if (null === ($currencies = $this->readEntry($locale, array('Currencies')))) { return array(); } diff --git a/src/Symfony/Component/Intl/ResourceBundle/CurrencyBundleInterface.php b/src/Symfony/Component/Intl/ResourceBundle/CurrencyBundleInterface.php index 596f6e207d..65eeeaab69 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/CurrencyBundleInterface.php +++ b/src/Symfony/Component/Intl/ResourceBundle/CurrencyBundleInterface.php @@ -21,31 +21,34 @@ interface CurrencyBundleInterface extends ResourceBundleInterface /** * Returns the symbol used for a currency. * - * @param string $locale The locale to return the result in. * @param string $currency A currency code (e.g. "EUR"). + * @param string $locale Optional. The locale to return the result in. + * Defaults to {@link \Locale::getLocale()}. * * @return string|null The currency symbol or NULL if not found. */ - public function getCurrencySymbol($locale, $currency); + public function getCurrencySymbol($currency, $locale = null); /** * Returns the name of a currency. * - * @param string $locale The locale to return the name in. * @param string $currency A currency code (e.g. "EUR"). + * @param string $locale Optional. The locale to return the name in. + * Defaults to {@link \Locale::getLocale()}. * * @return string|null The name of the currency or NULL if not found. */ - public function getCurrencyName($locale, $currency); + public function getCurrencyName($currency, $locale = null); /** * Returns the names of all known currencies. * - * @param string $locale The locale to return the names in. + * @param string $locale Optional. The locale to return the names in. + * Defaults to {@link \Locale::getLocale()}. * * @return string[] A list of currency names indexed by currency codes. */ - public function getCurrencyNames($locale); + public function getCurrencyNames($locale = null); /** * Returns the number of digits after the comma of a currency. diff --git a/src/Symfony/Component/Intl/ResourceBundle/LanguageBundle.php b/src/Symfony/Component/Intl/ResourceBundle/LanguageBundle.php index 1c3dfced57..01adaed03a 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/LanguageBundle.php +++ b/src/Symfony/Component/Intl/ResourceBundle/LanguageBundle.php @@ -21,8 +21,12 @@ class LanguageBundle extends AbstractBundle implements LanguageBundleInterface /** * {@inheritdoc} */ - public function getLanguageName($locale, $lang, $region = null) + public function getLanguageName($lang, $region = null, $locale = null) { + if (null === $locale) { + $locale = \Locale::getDefault(); + } + if (null === ($languages = $this->readEntry($locale, array('Languages')))) { return array(); } @@ -39,8 +43,12 @@ class LanguageBundle extends AbstractBundle implements LanguageBundleInterface /** * {@inheritdoc} */ - public function getLanguageNames($locale) + public function getLanguageNames($locale = null) { + if (null === $locale) { + $locale = \Locale::getDefault(); + } + if (null === ($languages = $this->readEntry($locale, array('Languages')))) { return array(); } @@ -55,8 +63,12 @@ class LanguageBundle extends AbstractBundle implements LanguageBundleInterface /** * {@inheritdoc} */ - public function getScriptName($locale, $script, $lang = null) + public function getScriptName($script, $lang = null, $locale = null) { + if (null === $locale) { + $locale = \Locale::getDefault(); + } + $data = $this->read($locale); // Some languages are translated together with their script, @@ -84,8 +96,12 @@ class LanguageBundle extends AbstractBundle implements LanguageBundleInterface /** * {@inheritdoc} */ - public function getScriptNames($locale) + public function getScriptNames($locale = null) { + if (null === $locale) { + $locale = \Locale::getDefault(); + } + if (null === ($scripts = $this->readEntry($locale, array('Scripts')))) { return array(); } diff --git a/src/Symfony/Component/Intl/ResourceBundle/LanguageBundleInterface.php b/src/Symfony/Component/Intl/ResourceBundle/LanguageBundleInterface.php index 62a0eba250..57c18ef6fc 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/LanguageBundleInterface.php +++ b/src/Symfony/Component/Intl/ResourceBundle/LanguageBundleInterface.php @@ -21,40 +21,44 @@ interface LanguageBundleInterface extends ResourceBundleInterface /** * Returns the name of a language. * - * @param string $locale The locale to return the name in. * @param string $lang A language code (e.g. "en"). * @param string|null $region Optional. A region code (e.g. "US"). + * @param string $locale Optional. The locale to return the name in. + * Defaults to {@link \Locale::getLocale()}. * * @return string|null The name of the language or NULL if not found. */ - public function getLanguageName($locale, $lang, $region = null); + public function getLanguageName($lang, $region = null, $locale = null); /** * Returns the names of all known languages. * - * @param string $locale The locale to return the names in. + * @param string $locale Optional. The locale to return the names in. + * Defaults to {@link \Locale::getLocale()}. * * @return string[] A list of language names indexed by language codes. */ - public function getLanguageNames($locale); + public function getLanguageNames($locale = null); /** * Returns the name of a script. * - * @param string $locale The locale to return the name in. * @param string $script A script code (e.g. "Hans"). * @param string $lang Optional. A language code (e.g. "zh"). + * @param string $locale Optional. The locale to return the name in. + * Defaults to {@link \Locale::getLocale()}. * * @return string|null The name of the script or NULL if not found. */ - public function getScriptName($locale, $script, $lang = null); + public function getScriptName($script, $lang = null, $locale = null); /** * Returns the names of all known scripts. * - * @param string $locale The locale to return the names in. + * @param string $locale Optional. The locale to return the names in. + * Defaults to {@link \Locale::getLocale()}. * * @return string[] A list of script names indexed by script codes. */ - public function getScriptNames($locale); + public function getScriptNames($locale = null); } diff --git a/src/Symfony/Component/Intl/ResourceBundle/LocaleBundle.php b/src/Symfony/Component/Intl/ResourceBundle/LocaleBundle.php index 3f50d876db..6f6cdfcb18 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/LocaleBundle.php +++ b/src/Symfony/Component/Intl/ResourceBundle/LocaleBundle.php @@ -21,16 +21,24 @@ class LocaleBundle extends AbstractBundle implements LocaleBundleInterface /** * {@inheritdoc} */ - public function getLocaleName($locale, $ofLocale) + public function getLocaleName($ofLocale, $locale = null) { + if (null === $locale) { + $locale = \Locale::getDefault(); + } + return $this->readEntry($locale, array('Locales', $ofLocale)); } /** * {@inheritdoc} */ - public function getLocaleNames($locale) + public function getLocaleNames($locale = null) { + if (null === $locale) { + $locale = \Locale::getDefault(); + } + if (null === ($locales = $this->readEntry($locale, array('Locales')))) { return array(); } diff --git a/src/Symfony/Component/Intl/ResourceBundle/LocaleBundleInterface.php b/src/Symfony/Component/Intl/ResourceBundle/LocaleBundleInterface.php index d7e536486a..8f30595231 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/LocaleBundleInterface.php +++ b/src/Symfony/Component/Intl/ResourceBundle/LocaleBundleInterface.php @@ -21,19 +21,21 @@ interface LocaleBundleInterface extends ResourceBundleInterface /** * Returns the name of a locale. * - * @param string $locale The locale to return the name in. * @param string $ofLocale The locale to return the name of (e.g. "de_AT"). + * @param string $locale Optional. The locale to return the name in. + * Defaults to {@link \Locale::getLocale()}. * * @return string|null The name of the locale or NULL if not found. */ - public function getLocaleName($locale, $ofLocale); + public function getLocaleName($ofLocale, $locale = null); /** * Returns the names of all known locales. * - * @param string $locale The locale to return the name in. + * @param string $locale Optional. The locale to return the names in. + * Defaults to {@link \Locale::getLocale()}. * * @return string[] A list of locale names indexed by locale codes. */ - public function getLocaleNames($locale); + public function getLocaleNames($locale = null); } diff --git a/src/Symfony/Component/Intl/ResourceBundle/RegionBundle.php b/src/Symfony/Component/Intl/ResourceBundle/RegionBundle.php index 58ccfd4dc7..a3cd9bd39a 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/RegionBundle.php +++ b/src/Symfony/Component/Intl/ResourceBundle/RegionBundle.php @@ -21,16 +21,24 @@ class RegionBundle extends AbstractBundle implements RegionBundleInterface /** * {@inheritdoc} */ - public function getCountryName($locale, $country) + public function getCountryName($country, $locale = null) { + if (null === $locale) { + $locale = \Locale::getDefault(); + } + return $this->readEntry($locale, array('Countries', $country)); } /** * {@inheritdoc} */ - public function getCountryNames($locale) + public function getCountryNames($locale = null) { + if (null === $locale) { + $locale = \Locale::getDefault(); + } + if (null === ($countries = $this->readEntry($locale, array('Countries')))) { return array(); } diff --git a/src/Symfony/Component/Intl/ResourceBundle/RegionBundleInterface.php b/src/Symfony/Component/Intl/ResourceBundle/RegionBundleInterface.php index 835748b568..9fb6c9ec06 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/RegionBundleInterface.php +++ b/src/Symfony/Component/Intl/ResourceBundle/RegionBundleInterface.php @@ -21,19 +21,21 @@ interface RegionBundleInterface extends ResourceBundleInterface /** * Returns the name of a country. * - * @param string $locale The locale to return the name in. * @param string $country A country code (e.g. "US"). + * @param string $locale Optional. The locale to return the name in. + * Defaults to {@link \Locale::getLocale()}. * * @return string|null The name of the country or NULL if not found. */ - public function getCountryName($locale, $country); + public function getCountryName($country, $locale = null); /** * Returns the names of all known countries. * - * @param string $locale The locale to return the names in. + * @param string $locale Optional. The locale to return the names in. + * Defaults to {@link \Locale::getLocale()}. * * @return string[] A list of country names indexed by country codes. */ - public function getCountryNames($locale); + public function getCountryNames($locale = null); } diff --git a/src/Symfony/Component/Intl/Tests/ResourceBundle/CurrencyBundleTest.php b/src/Symfony/Component/Intl/Tests/ResourceBundle/CurrencyBundleTest.php index 4ee708a9fc..b66a6727bf 100644 --- a/src/Symfony/Component/Intl/Tests/ResourceBundle/CurrencyBundleTest.php +++ b/src/Symfony/Component/Intl/Tests/ResourceBundle/CurrencyBundleTest.php @@ -43,7 +43,7 @@ class CurrencyBundleTest extends \PHPUnit_Framework_TestCase ->with(self::RES_DIR, 'en', array('Currencies', 'EUR', 1)) ->will($this->returnValue('€')); - $this->assertSame('€', $this->bundle->getCurrencySymbol('en', 'EUR')); + $this->assertSame('€', $this->bundle->getCurrencySymbol('EUR', 'en')); } public function testGetCurrencyName() @@ -53,7 +53,7 @@ class CurrencyBundleTest extends \PHPUnit_Framework_TestCase ->with(self::RES_DIR, 'en', array('Currencies', 'EUR', 0)) ->will($this->returnValue('Euro')); - $this->assertSame('Euro', $this->bundle->getCurrencyName('en', 'EUR')); + $this->assertSame('Euro', $this->bundle->getCurrencyName('EUR', 'en')); } public function testGetCurrencyNames() diff --git a/src/Symfony/Component/Intl/Tests/ResourceBundle/LanguageBundleTest.php b/src/Symfony/Component/Intl/Tests/ResourceBundle/LanguageBundleTest.php index a14a101a57..a8a6662155 100644 --- a/src/Symfony/Component/Intl/Tests/ResourceBundle/LanguageBundleTest.php +++ b/src/Symfony/Component/Intl/Tests/ResourceBundle/LanguageBundleTest.php @@ -48,7 +48,7 @@ class LanguageBundleTest extends \PHPUnit_Framework_TestCase ->with(self::RES_DIR, 'en', array('Languages')) ->will($this->returnValue($languages)); - $this->assertSame('German', $this->bundle->getLanguageName('en', 'de')); + $this->assertSame('German', $this->bundle->getLanguageName('de', 'en')); } public function testGetLanguageNameWithRegion() @@ -64,7 +64,7 @@ class LanguageBundleTest extends \PHPUnit_Framework_TestCase ->with(self::RES_DIR, 'en', array('Languages')) ->will($this->returnValue($languages)); - $this->assertSame('British English', $this->bundle->getLanguageName('en', 'en', 'GB')); + $this->assertSame('British English', $this->bundle->getLanguageName('en', 'GB', 'en')); } public function testGetLanguageNameWithUntranslatedRegion() @@ -79,7 +79,7 @@ class LanguageBundleTest extends \PHPUnit_Framework_TestCase ->with(self::RES_DIR, 'en', array('Languages')) ->will($this->returnValue($languages)); - $this->assertSame('English', $this->bundle->getLanguageName('en', 'en', 'US')); + $this->assertSame('English', $this->bundle->getLanguageName('en', 'US', 'en')); } public function testGetLanguageNames() @@ -115,7 +115,7 @@ class LanguageBundleTest extends \PHPUnit_Framework_TestCase ->with(self::RES_DIR, 'en') ->will($this->returnValue($data)); - $this->assertSame('latin', $this->bundle->getScriptName('en', 'Latn')); + $this->assertSame('latin', $this->bundle->getScriptName('Latn', 'en')); } public function testGetScriptNameIncludedInLanguage() @@ -138,7 +138,7 @@ class LanguageBundleTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue($data)); // Null because the script is included in the language anyway - $this->assertNull($this->bundle->getScriptName('en', 'Hans', 'zh')); + $this->assertNull($this->bundle->getScriptName('Hans', 'zh', 'en')); } public function testGetScriptNameIncludedInLanguageInBraces() @@ -160,7 +160,7 @@ class LanguageBundleTest extends \PHPUnit_Framework_TestCase ->with(self::RES_DIR, 'en') ->will($this->returnValue($data)); - $this->assertSame('simplified', $this->bundle->getScriptName('en', 'Hans', 'zh')); + $this->assertSame('simplified', $this->bundle->getScriptName('Hans', 'zh', 'en')); } public function testGetScriptNameNoScriptsBlock() @@ -177,7 +177,7 @@ class LanguageBundleTest extends \PHPUnit_Framework_TestCase ->with(self::RES_DIR, 'en') ->will($this->returnValue($data)); - $this->assertNull($this->bundle->getScriptName('en', 'Latn')); + $this->assertNull($this->bundle->getScriptName('Latn', 'en')); } public function testGetScriptNames() diff --git a/src/Symfony/Component/Intl/Tests/ResourceBundle/LocaleBundleTest.php b/src/Symfony/Component/Intl/Tests/ResourceBundle/LocaleBundleTest.php index b323362374..0ff288ddab 100644 --- a/src/Symfony/Component/Intl/Tests/ResourceBundle/LocaleBundleTest.php +++ b/src/Symfony/Component/Intl/Tests/ResourceBundle/LocaleBundleTest.php @@ -44,7 +44,7 @@ class LocaleBundleTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue('German (Austria)')); - $this->assertSame('German (Austria)', $this->bundle->getLocaleName('en', 'de_AT')); + $this->assertSame('German (Austria)', $this->bundle->getLocaleName('de_AT', 'en')); } public function testGetLocaleNames() diff --git a/src/Symfony/Component/Intl/Tests/ResourceBundle/RegionBundleTest.php b/src/Symfony/Component/Intl/Tests/ResourceBundle/RegionBundleTest.php index 23ed8baef3..40a7692cf4 100644 --- a/src/Symfony/Component/Intl/Tests/ResourceBundle/RegionBundleTest.php +++ b/src/Symfony/Component/Intl/Tests/ResourceBundle/RegionBundleTest.php @@ -43,7 +43,7 @@ class RegionBundleTest extends \PHPUnit_Framework_TestCase ->with(self::RES_DIR, 'en', array('Countries', 'AT')) ->will($this->returnValue('Austria')); - $this->assertSame('Austria', $this->bundle->getCountryName('en', 'AT')); + $this->assertSame('Austria', $this->bundle->getCountryName('AT', 'en')); } public function testGetCountryNames()