From 4ecbd201ec36def4739991a72177f3302219e4eb Mon Sep 17 00:00:00 2001 From: Leandro Gehlen Date: Thu, 29 May 2014 11:53:42 -0300 Subject: [PATCH 01/10] Added `yii\i18n\Formatter::intlCurrencySymbol` --- framework/i18n/Formatter.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/framework/i18n/Formatter.php b/framework/i18n/Formatter.php index 7ada01c..e81fe2e 100644 --- a/framework/i18n/Formatter.php +++ b/framework/i18n/Formatter.php @@ -73,6 +73,11 @@ class Formatter extends \yii\base\Formatter * If not set, the thousand separator corresponding to [[locale]] will be used. */ public $thousandSeparator; + /** + * @var string the international curency symbol displayed when formatting a number. + * If not set, the thousand separator corresponding to [[locale]] will be used. + */ + public $intlCurrencySymbol; /** * Initializes the component. @@ -88,7 +93,7 @@ class Formatter extends \yii\base\Formatter if ($this->locale === null) { $this->locale = Yii::$app->language; } - if ($this->decimalSeparator === null || $this->thousandSeparator === null) { + if ($this->decimalSeparator === null || $this->thousandSeparator === null || $this->intlCurrencySymbol === null) { $formatter = new NumberFormatter($this->locale, NumberFormatter::DECIMAL); if ($this->decimalSeparator === null) { $this->decimalSeparator = $formatter->getSymbol(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL); @@ -96,6 +101,9 @@ class Formatter extends \yii\base\Formatter if ($this->thousandSeparator === null) { $this->thousandSeparator = $formatter->getSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL); } + if ($this->intlCurrencySymbol === null) { + $this->intlCurrencySymbol = $formatter->getSymbol(NumberFormatter::INTL_CURRENCY_SYMBOL); + } } parent::init(); @@ -261,11 +269,15 @@ class Formatter extends \yii\base\Formatter * for details on how to specify a format. * @return string the formatted result. */ - public function asCurrency($value, $currency = 'USD', $format = null) + public function asCurrency($value, $currency = null, $format = null) { if ($value === null) { return $this->nullDisplay; } + + if ($currency === null){ + $currency = $this->intlCurrencySymbol; + } return $this->createNumberFormatter(NumberFormatter::CURRENCY, $format)->formatCurrency($value, $currency); } From f7488579b21a0bc19793f3950c2eb0b3ac93bab5 Mon Sep 17 00:00:00 2001 From: leandrogehlen Date: Thu, 29 May 2014 13:42:46 -0300 Subject: [PATCH 02/10] Renamed Formatter::intlCurrencySymbol to currencySymbol --- framework/i18n/Formatter.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/framework/i18n/Formatter.php b/framework/i18n/Formatter.php index e81fe2e..e7b8759 100644 --- a/framework/i18n/Formatter.php +++ b/framework/i18n/Formatter.php @@ -77,7 +77,7 @@ class Formatter extends \yii\base\Formatter * @var string the international curency symbol displayed when formatting a number. * If not set, the thousand separator corresponding to [[locale]] will be used. */ - public $intlCurrencySymbol; + public $currencySymbol; /** * Initializes the component. @@ -93,7 +93,7 @@ class Formatter extends \yii\base\Formatter if ($this->locale === null) { $this->locale = Yii::$app->language; } - if ($this->decimalSeparator === null || $this->thousandSeparator === null || $this->intlCurrencySymbol === null) { + if ($this->decimalSeparator === null || $this->thousandSeparator === null || $this->currencySymbol === null) { $formatter = new NumberFormatter($this->locale, NumberFormatter::DECIMAL); if ($this->decimalSeparator === null) { $this->decimalSeparator = $formatter->getSymbol(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL); @@ -101,8 +101,8 @@ class Formatter extends \yii\base\Formatter if ($this->thousandSeparator === null) { $this->thousandSeparator = $formatter->getSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL); } - if ($this->intlCurrencySymbol === null) { - $this->intlCurrencySymbol = $formatter->getSymbol(NumberFormatter::INTL_CURRENCY_SYMBOL); + if ($this->currencySymbol === null) { + $this->currencySymbol = $formatter->getSymbol(NumberFormatter::INTL_CURRENCY_SYMBOL); } } @@ -276,7 +276,7 @@ class Formatter extends \yii\base\Formatter } if ($currency === null){ - $currency = $this->intlCurrencySymbol; + $currency = $this->currencySymbol; } return $this->createNumberFormatter(NumberFormatter::CURRENCY, $format)->formatCurrency($value, $currency); From 55ad347e6242f427b8e4996d217a9dc94eb8a304 Mon Sep 17 00:00:00 2001 From: leandrogehlen Date: Thu, 29 May 2014 13:52:16 -0300 Subject: [PATCH 03/10] Fixes typo --- framework/i18n/Formatter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/i18n/Formatter.php b/framework/i18n/Formatter.php index e7b8759..5aa5795 100644 --- a/framework/i18n/Formatter.php +++ b/framework/i18n/Formatter.php @@ -74,8 +74,8 @@ class Formatter extends \yii\base\Formatter */ public $thousandSeparator; /** - * @var string the international curency symbol displayed when formatting a number. - * If not set, the thousand separator corresponding to [[locale]] will be used. + * @var string the international currency symbol displayed when formatting a number. + * If not set, the currency symbol corresponding to [[locale]] will be used. */ public $currencySymbol; From 0efa0faaf74ebe13876904976f27f83952847634 Mon Sep 17 00:00:00 2001 From: leandrogehlen Date: Fri, 30 May 2014 16:23:25 -0300 Subject: [PATCH 04/10] Added comment about $currency when it is null --- framework/i18n/Formatter.php | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/i18n/Formatter.php b/framework/i18n/Formatter.php index 5aa5795..e57a66a 100644 --- a/framework/i18n/Formatter.php +++ b/framework/i18n/Formatter.php @@ -265,6 +265,7 @@ class Formatter extends \yii\base\Formatter * Formats the value as a currency number. * @param mixed $value the value to be formatted * @param string $currency the 3-letter ISO 4217 currency code indicating the currency to use. + * If null, [[currencySymbol]] will be used. * @param string $format the format to be used. Please refer to [ICU manual](http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#_details) * for details on how to specify a format. * @return string the formatted result. From b2e8c07e4fcc202b414646ece5767fb3965b7fbf Mon Sep 17 00:00:00 2001 From: leandrogehlen Date: Fri, 30 May 2014 16:23:49 -0300 Subject: [PATCH 05/10] changelog --- framework/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 93502f9..30635e2 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -75,6 +75,7 @@ Yii Framework 2 Change Log - Enh: Added support for using path alias with `FileDependency::fileName` (qiangxue) - Enh: Added param `hideOnSinglePage` to `yii\widgets\LinkPager` (arturf) - Enh: Added support for array attributes in `in` validator (creocoder) +- Enh: Added property `currencySymbol` to `yii\i18n\Formatter` (leandrogehlen) - Chg #2898: `yii\console\controllers\AssetController` is now using hashes instead of timestamps (samdark) - Chg #2913: RBAC `DbManager` is now initialized via migration (samdark) - Chg #3036: Upgraded Twitter Bootstrap to 3.1.x (qiangxue) From f072b5563886080d0280298d468bded4aeac9cb1 Mon Sep 17 00:00:00 2001 From: leandrogehlen Date: Sat, 31 May 2014 10:38:31 -0300 Subject: [PATCH 06/10] Renamed `Formatter::currencySymbol` to `currencyCode` --- framework/i18n/Formatter.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/framework/i18n/Formatter.php b/framework/i18n/Formatter.php index e57a66a..6307f8b 100644 --- a/framework/i18n/Formatter.php +++ b/framework/i18n/Formatter.php @@ -77,7 +77,7 @@ class Formatter extends \yii\base\Formatter * @var string the international currency symbol displayed when formatting a number. * If not set, the currency symbol corresponding to [[locale]] will be used. */ - public $currencySymbol; + public $currencyCode; /** * Initializes the component. @@ -93,7 +93,7 @@ class Formatter extends \yii\base\Formatter if ($this->locale === null) { $this->locale = Yii::$app->language; } - if ($this->decimalSeparator === null || $this->thousandSeparator === null || $this->currencySymbol === null) { + if ($this->decimalSeparator === null || $this->thousandSeparator === null || $this->currencyCode === null) { $formatter = new NumberFormatter($this->locale, NumberFormatter::DECIMAL); if ($this->decimalSeparator === null) { $this->decimalSeparator = $formatter->getSymbol(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL); @@ -101,8 +101,8 @@ class Formatter extends \yii\base\Formatter if ($this->thousandSeparator === null) { $this->thousandSeparator = $formatter->getSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL); } - if ($this->currencySymbol === null) { - $this->currencySymbol = $formatter->getSymbol(NumberFormatter::INTL_CURRENCY_SYMBOL); + if ($this->currencyCode === null) { + $this->currencyCode = $formatter->getSymbol(NumberFormatter::INTL_CURRENCY_SYMBOL); } } @@ -277,7 +277,7 @@ class Formatter extends \yii\base\Formatter } if ($currency === null){ - $currency = $this->currencySymbol; + $currency = $this->currencyCode; } return $this->createNumberFormatter(NumberFormatter::CURRENCY, $format)->formatCurrency($value, $currency); From 95f87f77c47afe1b396dffd8ed690415d2e0a5c6 Mon Sep 17 00:00:00 2001 From: leandrogehlen Date: Sat, 31 May 2014 10:40:10 -0300 Subject: [PATCH 07/10] Changelog --- framework/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 30635e2..f171c20 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -75,7 +75,7 @@ Yii Framework 2 Change Log - Enh: Added support for using path alias with `FileDependency::fileName` (qiangxue) - Enh: Added param `hideOnSinglePage` to `yii\widgets\LinkPager` (arturf) - Enh: Added support for array attributes in `in` validator (creocoder) -- Enh: Added property `currencySymbol` to `yii\i18n\Formatter` (leandrogehlen) +- Enh: Added property `currencyCode` to `yii\i18n\Formatter` (leandrogehlen) - Chg #2898: `yii\console\controllers\AssetController` is now using hashes instead of timestamps (samdark) - Chg #2913: RBAC `DbManager` is now initialized via migration (samdark) - Chg #3036: Upgraded Twitter Bootstrap to 3.1.x (qiangxue) From 51c162d65e9823c7da71dad2af087ff15bcda0e1 Mon Sep 17 00:00:00 2001 From: leandrogehlen Date: Sat, 31 May 2014 10:42:04 -0300 Subject: [PATCH 08/10] Fixes typo --- framework/i18n/Formatter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/i18n/Formatter.php b/framework/i18n/Formatter.php index 6307f8b..c6a72d0 100644 --- a/framework/i18n/Formatter.php +++ b/framework/i18n/Formatter.php @@ -265,7 +265,7 @@ class Formatter extends \yii\base\Formatter * Formats the value as a currency number. * @param mixed $value the value to be formatted * @param string $currency the 3-letter ISO 4217 currency code indicating the currency to use. - * If null, [[currencySymbol]] will be used. + * If null, [[currencyCode]] will be used. * @param string $format the format to be used. Please refer to [ICU manual](http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#_details) * for details on how to specify a format. * @return string the formatted result. From fbb2d940ec4b8e7a3782f9ea4fe06dd2af483528 Mon Sep 17 00:00:00 2001 From: leandrogehlen Date: Sat, 31 May 2014 18:35:20 -0300 Subject: [PATCH 09/10] Adjusted changelog --- framework/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index f171c20..6b81ddd 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -63,6 +63,7 @@ Yii Framework 2 Change Log - Enh #3562: Adding rotateByCopy to yii\log\FileTarget (pawzar) - Enh #3574: Add integrity check support for SQLite (zeeke) - Enh #3597: Nested array support for HTML5 custom "data-*" attributes (armab) +- Enh #3631: Added property `currencyCode` to `yii\i18n\Formatter` (leandrogehlen) - Enh: Added support for using sub-queries when building a DB query with `IN` condition (qiangxue) - Enh: Supported adding a new response formatter without the need to reconfigure existing formatters (qiangxue) - Enh: Added `yii\web\UrlManager::addRules()` to simplify adding new URL rules (qiangxue) @@ -75,7 +76,6 @@ Yii Framework 2 Change Log - Enh: Added support for using path alias with `FileDependency::fileName` (qiangxue) - Enh: Added param `hideOnSinglePage` to `yii\widgets\LinkPager` (arturf) - Enh: Added support for array attributes in `in` validator (creocoder) -- Enh: Added property `currencyCode` to `yii\i18n\Formatter` (leandrogehlen) - Chg #2898: `yii\console\controllers\AssetController` is now using hashes instead of timestamps (samdark) - Chg #2913: RBAC `DbManager` is now initialized via migration (samdark) - Chg #3036: Upgraded Twitter Bootstrap to 3.1.x (qiangxue) From e6f05c6b9adb933353177d07fc00f3a3c3b12ff8 Mon Sep 17 00:00:00 2001 From: leandrogehlen Date: Sat, 31 May 2014 18:37:53 -0300 Subject: [PATCH 10/10] Adjusted documentation --- framework/i18n/Formatter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/i18n/Formatter.php b/framework/i18n/Formatter.php index c6a72d0..98f5287 100644 --- a/framework/i18n/Formatter.php +++ b/framework/i18n/Formatter.php @@ -74,8 +74,8 @@ class Formatter extends \yii\base\Formatter */ public $thousandSeparator; /** - * @var string the international currency symbol displayed when formatting a number. - * If not set, the currency symbol corresponding to [[locale]] will be used. + * @var string the international currency code displayed when formatting a number. + * If not set, the currency code corresponding to [[locale]] will be used. */ public $currencyCode;