Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2cd1be8

Browse files
committed
[Intl] Made the $locale parameter optional in the bundle interfaces
1 parent b9e9cb2 commit 2cd1be8

14 files changed

+114
-59
lines changed

src/Symfony/Component/Intl/NumberFormatter/StubNumberFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public function formatCurrency($value, $currency)
300300
return $this->format($value);
301301
}
302302

303-
$symbol = Intl::getCurrencyBundle()->getCurrencySymbol('en', $currency);
303+
$symbol = Intl::getCurrencyBundle()->getCurrencySymbol($currency, 'en');
304304
$fractionDigits = Intl::getCurrencyBundle()->getFractionDigits($currency);
305305

306306
$value = $this->roundCurrency($value, $currency);

src/Symfony/Component/Intl/README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ Numbers can be formatted with the [`\NumberFormatter`] [3] class. The following
5555
methods are supported. All other methods are not supported and will throw an
5656
exception when used.
5757

58-
##### __construct($locale = 'en', $style = null, $pattern = null)
58+
##### __construct($locale = $style = null, $pattern = null)
5959

6060
The only supported locale is "en". The supported styles are
6161
`\NumberFormatter::DECIMAL` and `\NumberFormatter::CURRENCY`. The argument
6262
`$pattern` may not be used.
6363

64-
##### ::create($locale = 'en', $style = null, $pattern = null)
64+
##### ::create($locale = $style = null, $pattern = null)
6565

6666
See `__construct()`.
6767

@@ -115,41 +115,41 @@ Languages and Scripts
115115
The translations of language and script names can be found in the language
116116
bundle.
117117
118-
$languages = Intl::getLanguageBundle()->getLanguageNames('en');
118+
$languages = Intl::getLanguageBundle()->getLanguageNames();
119119
// => array('ab' => 'Abkhazian', ...)
120120
121-
$language = Intl::getLanguageBundle()->getLanguageName('en', 'de');
121+
$language = Intl::getLanguageBundle()->getLanguageName('de');
122122
// => 'German'
123123
124-
$language = Intl::getLanguageBundle()->getLanguageName('en', 'de', 'AT);
124+
$language = Intl::getLanguageBundle()->getLanguageName('de', 'AT);
125125
// => 'Austrian German'
126126
127-
$scripts = Intl::getLanguageBundle()->getScriptNames('en');
127+
$scripts = Intl::getLanguageBundle()->getScriptNames();
128128
// => array('Arab' => 'Arabic', ...)
129129
130-
$script = Intl::getLanguageBundle()->getScriptName('en', 'Hans');
130+
$script = Intl::getLanguageBundle()->getScriptName('Hans');
131131
// => 'Simplified'
132132
133133
Countries
134134
~~~~~~~~~
135135
136136
The translations of country names can be found in the region bundle.
137137
138-
$countries = Intl::getRegionBundle()->getCountryNames('en');
138+
$countries = Intl::getRegionBundle()->getCountryNames();
139139
// => array('AF' => 'Afghanistan', ...)
140140
141-
$country = Intl::getRegionBundle()->getCountryName('en', 'GB');
141+
$country = Intl::getRegionBundle()->getCountryName('GB');
142142
// => 'United Kingdom'
143143
144144
Locales
145145
~~~~~~~
146146
147147
The translations of locale names can be found in the locale bundle.
148148
149-
$locales = Intl::getLocaleBundle()->getLocaleNames('en');
149+
$locales = Intl::getLocaleBundle()->getLocaleNames();
150150
// => array('af' => 'Afrikaans', ...)
151151
152-
$locale = Intl::getLocaleBundle()->getLocaleName('en', 'zh_Hans_MO');
152+
$locale = Intl::getLocaleBundle()->getLocaleName('zh_Hans_MO');
153153
// => 'Chinese (Simplified, Macau SAR China)'
154154
155155
Currencies
@@ -158,13 +158,13 @@ Currencies
158158
The translations of currency names and other currency-related information can
159159
be found in the currency bundle.
160160
161-
$currencies = Intl::getCurrencyBundle()->getCurrencyNames('en');
161+
$currencies = Intl::getCurrencyBundle()->getCurrencyNames();
162162
// => array('AFN' => 'Afghan Afghani', ...)
163163
164-
$currency = Intl::getCurrencyBundle()->getCurrencyNames('en', 'INR');
164+
$currency = Intl::getCurrencyBundle()->getCurrencyNames('INR');
165165
// => 'Indian Rupee'
166166
167-
$symbol = Intl::getCurrencyBundle()->getCurrencyNames('en', 'INR');
167+
$symbol = Intl::getCurrencyBundle()->getCurrencyNames('INR');
168168
// => '₹'
169169
170170
$fractionDigits = Intl::getCurrencyBundle()->getFractionDigits('INR');

src/Symfony/Component/Intl/ResourceBundle/CurrencyBundle.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,36 @@ class CurrencyBundle extends AbstractBundle implements CurrencyBundleInterface
2929
/**
3030
* {@inheritdoc}
3131
*/
32-
public function getCurrencySymbol($locale, $currency)
32+
public function getCurrencySymbol($currency, $locale = null)
3333
{
34+
if (null === $locale) {
35+
$locale = \Locale::getDefault();
36+
}
37+
3438
return $this->readEntry($locale, array('Currencies', $currency, static::INDEX_SYMBOL));
3539
}
3640

3741
/**
3842
* {@inheritdoc}
3943
*/
40-
public function getCurrencyName($locale, $currency)
44+
public function getCurrencyName($currency, $locale = null)
4145
{
46+
if (null === $locale) {
47+
$locale = \Locale::getDefault();
48+
}
49+
4250
return $this->readEntry($locale, array('Currencies', $currency, static::INDEX_NAME));
4351
}
4452

4553
/**
4654
* {@inheritdoc}
4755
*/
48-
public function getCurrencyNames($locale)
56+
public function getCurrencyNames($locale = null)
4957
{
58+
if (null === $locale) {
59+
$locale = \Locale::getDefault();
60+
}
61+
5062
if (null === ($currencies = $this->readEntry($locale, array('Currencies')))) {
5163
return array();
5264
}

src/Symfony/Component/Intl/ResourceBundle/CurrencyBundleInterface.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,34 @@ interface CurrencyBundleInterface extends ResourceBundleInterface
2121
/**
2222
* Returns the symbol used for a currency.
2323
*
24-
* @param string $locale The locale to return the result in.
2524
* @param string $currency A currency code (e.g. "EUR").
25+
* @param string $locale Optional. The locale to return the result in.
26+
* Defaults to {@link \Locale::getLocale()}.
2627
*
2728
* @return string|null The currency symbol or NULL if not found.
2829
*/
29-
public function getCurrencySymbol($locale, $currency);
30+
public function getCurrencySymbol($currency, $locale = null);
3031

3132
/**
3233
* Returns the name of a currency.
3334
*
34-
* @param string $locale The locale to return the name in.
3535
* @param string $currency A currency code (e.g. "EUR").
36+
* @param string $locale Optional. The locale to return the name in.
37+
* Defaults to {@link \Locale::getLocale()}.
3638
*
3739
* @return string|null The name of the currency or NULL if not found.
3840
*/
39-
public function getCurrencyName($locale, $currency);
41+
public function getCurrencyName($currency, $locale = null);
4042

4143
/**
4244
* Returns the names of all known currencies.
4345
*
44-
* @param string $locale The locale to return the names in.
46+
* @param string $locale Optional. The locale to return the names in.
47+
* Defaults to {@link \Locale::getLocale()}.
4548
*
4649
* @return string[] A list of currency names indexed by currency codes.
4750
*/
48-
public function getCurrencyNames($locale);
51+
public function getCurrencyNames($locale = null);
4952

5053
/**
5154
* Returns the number of digits after the comma of a currency.

src/Symfony/Component/Intl/ResourceBundle/LanguageBundle.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ class LanguageBundle extends AbstractBundle implements LanguageBundleInterface
2121
/**
2222
* {@inheritdoc}
2323
*/
24-
public function getLanguageName($locale, $lang, $region = null)
24+
public function getLanguageName($lang, $region = null, $locale = null)
2525
{
26+
if (null === $locale) {
27+
$locale = \Locale::getDefault();
28+
}
29+
2630
if (null === ($languages = $this->readEntry($locale, array('Languages')))) {
2731
return array();
2832
}
@@ -39,8 +43,12 @@ public function getLanguageName($locale, $lang, $region = null)
3943
/**
4044
* {@inheritdoc}
4145
*/
42-
public function getLanguageNames($locale)
46+
public function getLanguageNames($locale = null)
4347
{
48+
if (null === $locale) {
49+
$locale = \Locale::getDefault();
50+
}
51+
4452
if (null === ($languages = $this->readEntry($locale, array('Languages')))) {
4553
return array();
4654
}
@@ -55,8 +63,12 @@ public function getLanguageNames($locale)
5563
/**
5664
* {@inheritdoc}
5765
*/
58-
public function getScriptName($locale, $script, $lang = null)
66+
public function getScriptName($script, $lang = null, $locale = null)
5967
{
68+
if (null === $locale) {
69+
$locale = \Locale::getDefault();
70+
}
71+
6072
$data = $this->read($locale);
6173

6274
// Some languages are translated together with their script,
@@ -84,8 +96,12 @@ public function getScriptName($locale, $script, $lang = null)
8496
/**
8597
* {@inheritdoc}
8698
*/
87-
public function getScriptNames($locale)
99+
public function getScriptNames($locale = null)
88100
{
101+
if (null === $locale) {
102+
$locale = \Locale::getDefault();
103+
}
104+
89105
if (null === ($scripts = $this->readEntry($locale, array('Scripts')))) {
90106
return array();
91107
}

src/Symfony/Component/Intl/ResourceBundle/LanguageBundleInterface.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,44 @@ interface LanguageBundleInterface extends ResourceBundleInterface
2121
/**
2222
* Returns the name of a language.
2323
*
24-
* @param string $locale The locale to return the name in.
2524
* @param string $lang A language code (e.g. "en").
2625
* @param string|null $region Optional. A region code (e.g. "US").
26+
* @param string $locale Optional. The locale to return the name in.
27+
* Defaults to {@link \Locale::getLocale()}.
2728
*
2829
* @return string|null The name of the language or NULL if not found.
2930
*/
30-
public function getLanguageName($locale, $lang, $region = null);
31+
public function getLanguageName($lang, $region = null, $locale = null);
3132

3233
/**
3334
* Returns the names of all known languages.
3435
*
35-
* @param string $locale The locale to return the names in.
36+
* @param string $locale Optional. The locale to return the names in.
37+
* Defaults to {@link \Locale::getLocale()}.
3638
*
3739
* @return string[] A list of language names indexed by language codes.
3840
*/
39-
public function getLanguageNames($locale);
41+
public function getLanguageNames($locale = null);
4042

4143
/**
4244
* Returns the name of a script.
4345
*
44-
* @param string $locale The locale to return the name in.
4546
* @param string $script A script code (e.g. "Hans").
4647
* @param string $lang Optional. A language code (e.g. "zh").
48+
* @param string $locale Optional. The locale to return the name in.
49+
* Defaults to {@link \Locale::getLocale()}.
4750
*
4851
* @return string|null The name of the script or NULL if not found.
4952
*/
50-
public function getScriptName($locale, $script, $lang = null);
53+
public function getScriptName($script, $lang = null, $locale = null);
5154

5255
/**
5356
* Returns the names of all known scripts.
5457
*
55-
* @param string $locale The locale to return the names in.
58+
* @param string $locale Optional. The locale to return the names in.
59+
* Defaults to {@link \Locale::getLocale()}.
5660
*
5761
* @return string[] A list of script names indexed by script codes.
5862
*/
59-
public function getScriptNames($locale);
63+
public function getScriptNames($locale = null);
6064
}

src/Symfony/Component/Intl/ResourceBundle/LocaleBundle.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,24 @@ class LocaleBundle extends AbstractBundle implements LocaleBundleInterface
2121
/**
2222
* {@inheritdoc}
2323
*/
24-
public function getLocaleName($locale, $ofLocale)
24+
public function getLocaleName($ofLocale, $locale = null)
2525
{
26+
if (null === $locale) {
27+
$locale = \Locale::getDefault();
28+
}
29+
2630
return $this->readEntry($locale, array('Locales', $ofLocale));
2731
}
2832

2933
/**
3034
* {@inheritdoc}
3135
*/
32-
public function getLocaleNames($locale)
36+
public function getLocaleNames($locale = null)
3337
{
38+
if (null === $locale) {
39+
$locale = \Locale::getDefault();
40+
}
41+
3442
if (null === ($locales = $this->readEntry($locale, array('Locales')))) {
3543
return array();
3644
}

src/Symfony/Component/Intl/ResourceBundle/LocaleBundleInterface.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,21 @@ interface LocaleBundleInterface extends ResourceBundleInterface
2121
/**
2222
* Returns the name of a locale.
2323
*
24-
* @param string $locale The locale to return the name in.
2524
* @param string $ofLocale The locale to return the name of (e.g. "de_AT").
25+
* @param string $locale Optional. The locale to return the name in.
26+
* Defaults to {@link \Locale::getLocale()}.
2627
*
2728
* @return string|null The name of the locale or NULL if not found.
2829
*/
29-
public function getLocaleName($locale, $ofLocale);
30+
public function getLocaleName($ofLocale, $locale = null);
3031

3132
/**
3233
* Returns the names of all known locales.
3334
*
34-
* @param string $locale The locale to return the name in.
35+
* @param string $locale Optional. The locale to return the names in.
36+
* Defaults to {@link \Locale::getLocale()}.
3537
*
3638
* @return string[] A list of locale names indexed by locale codes.
3739
*/
38-
public function getLocaleNames($locale);
40+
public function getLocaleNames($locale = null);
3941
}

src/Symfony/Component/Intl/ResourceBundle/RegionBundle.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,24 @@ class RegionBundle extends AbstractBundle implements RegionBundleInterface
2121
/**
2222
* {@inheritdoc}
2323
*/
24-
public function getCountryName($locale, $country)
24+
public function getCountryName($country, $locale = null)
2525
{
26+
if (null === $locale) {
27+
$locale = \Locale::getDefault();
28+
}
29+
2630
return $this->readEntry($locale, array('Countries', $country));
2731
}
2832

2933
/**
3034
* {@inheritdoc}
3135
*/
32-
public function getCountryNames($locale)
36+
public function getCountryNames($locale = null)
3337
{
38+
if (null === $locale) {
39+
$locale = \Locale::getDefault();
40+
}
41+
3442
if (null === ($countries = $this->readEntry($locale, array('Countries')))) {
3543
return array();
3644
}

src/Symfony/Component/Intl/ResourceBundle/RegionBundleInterface.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,21 @@ interface RegionBundleInterface extends ResourceBundleInterface
2121
/**
2222
* Returns the name of a country.
2323
*
24-
* @param string $locale The locale to return the name in.
2524
* @param string $country A country code (e.g. "US").
25+
* @param string $locale Optional. The locale to return the name in.
26+
* Defaults to {@link \Locale::getLocale()}.
2627
*
2728
* @return string|null The name of the country or NULL if not found.
2829
*/
29-
public function getCountryName($locale, $country);
30+
public function getCountryName($country, $locale = null);
3031

3132
/**
3233
* Returns the names of all known countries.
3334
*
34-
* @param string $locale The locale to return the names in.
35+
* @param string $locale Optional. The locale to return the names in.
36+
* Defaults to {@link \Locale::getLocale()}.
3537
*
3638
* @return string[] A list of country names indexed by country codes.
3739
*/
38-
public function getCountryNames($locale);
40+
public function getCountryNames($locale = null);
3941
}

0 commit comments

Comments
 (0)