Skip to content

Commit afdbb5a

Browse files
committed
MAGETWO-34390: Stabilization of replacing Zend_Locale with Native PHP Implementation
1 parent 56cfe16 commit afdbb5a

File tree

16 files changed

+147
-104
lines changed

16 files changed

+147
-104
lines changed

app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
namespace Magento\CurrencySymbol\Model\System;
8+
use Magento\Framework\Locale\Bundle\CurrencyBundle;
89

910
/**
1011
* Custom currency symbol model
@@ -196,7 +197,7 @@ public function getCurrencySymbolsData()
196197
$currentSymbols = $this->_unserializeStoreConfig(self::XML_PATH_CUSTOM_CURRENCY_SYMBOL);
197198

198199
foreach ($allowedCurrencies as $code) {
199-
$currencies = (new \ResourceBundle($this->localeResolver->getLocale(), 'ICUDATA-curr'))['Currencies'];
200+
$currencies = (new CurrencyBundle())->get($this->localeResolver->getLocale())['Currencies'];
200201
$symbol = $currencies[$code][0] ?: $code;
201202
$name = $currencies[$code][1] ?: $code;
202203
$this->_symbolsData[$code] = ['parentSymbol' => $symbol, 'displayName' => $name];

app/code/Magento/Dhl/Setup/InstallData.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Dhl\Setup;
88

9+
use Magento\Framework\Locale\Bundle\DataBundle;
910
use Magento\Framework\Locale\ResolverInterface;
1011
use Magento\Framework\Setup\InstallDataInterface;
1112
use Magento\Framework\Setup\ModuleContextInterface;
@@ -38,10 +39,9 @@ public function __construct(ResolverInterface $localeResolver)
3839
*/
3940
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
4041
{
41-
$days = (new \ResourceBundle(
42-
$this->localeResolver->getLocale(),
43-
'ICUDATA'
44-
))['calendar']['gregorian']['dayNames']['format']['abbreviated'];
42+
$days = (new DataBundle())->get(
43+
$this->localeResolver->getLocale()
44+
)['calendar']['gregorian']['dayNames']['format']['abbreviated'];
4545

4646
$select = $setup->getConnection()->select()->from(
4747
$setup->getTable('core_config_data'),

app/code/Magento/Directory/Block/Currency.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010
namespace Magento\Directory\Block;
1111

12+
use Magento\Framework\Locale\Bundle\CurrencyBundle as CurrencyBundle;
13+
1214
class Currency extends \Magento\Framework\View\Element\Template
1315
{
1416
/**
@@ -78,9 +80,9 @@ public function getCurrencies()
7880

7981
foreach ($codes as $code) {
8082
if (isset($rates[$code])) {
81-
$allCurrencies = (new \ResourceBundle(
82-
$this->localeResolver->getLocale(), 'ICUDATA-curr'
83-
))['Currencies'];
83+
$allCurrencies = (new CurrencyBundle())->get(
84+
$this->localeResolver->getLocale()
85+
)['Currencies'];
8486
$currencies[$code] = $allCurrencies[$code][1] ?: $code;
8587
}
8688
}

app/code/Magento/Payment/Model/Config.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Payment\Model;
77

8+
use Magento\Framework\Locale\Bundle\DataBundle;
89
use Magento\Payment\Model\Method\AbstractMethod;
910
use Magento\Store\Model\ScopeInterface;
1011

@@ -140,10 +141,9 @@ public function getGroups()
140141
public function getMonths()
141142
{
142143
$data = [];
143-
$months = (new \ResourceBundle(
144-
$this->localeResolver->getLocale(),
145-
'ICUDATA'
146-
))['calendar']['gregorian']['monthNames']['format']['wide'];
144+
$months = (new DataBundle())->get(
145+
$this->localeResolver->getLocale()
146+
)['calendar']['gregorian']['monthNames']['format']['wide'];
147147
foreach ($months as $key => $value) {
148148
$monthNum = ++$key < 10 ? '0' . $key : $key;
149149
$data[$key] = $monthNum . ' - ' . $value;

app/code/Magento/Reports/Block/Adminhtml/Sales/Grid/Column/Renderer/Date.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento\Reports\Block\Adminhtml\Sales\Grid\Column\Renderer;
7+
use Magento\Framework\Locale\Bundle\DataBundle;
78

89
/**
910
* Adminhtml grid item renderer date
@@ -35,10 +36,9 @@ protected function _getFormat()
3536
if (!$format) {
3637
if (is_null(self::$_format)) {
3738
try {
38-
$formats = (new \ResourceBundle(
39-
$this->_localeResolver->getLocale(),
40-
'ICUDATA'
41-
))['calendar']['gregorian']['availableFormats'];
39+
$formats = (new DataBundle())->get(
40+
$this->_localeResolver->getLocale()
41+
)['calendar']['gregorian']['availableFormats'];
4242

4343
switch ($this->getColumn()->getPeriodType()) {
4444
case 'month':

dev/tests/unit/testsuite/Magento/Framework/Locale/ListsTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ public function testGetOptionCountries()
8585
$expectedResults = [
8686
['value' => 'AG', 'label' => 'Antigua and Barbuda'],
8787
['value' => 'BA', 'label' => 'Bosnia and Herzegovina'],
88-
['value' => 'CC', 'label' => 'Cocos (Keeling) Islands'],
8988
['value' => 'GS', 'label' => 'South Georgia & South Sandwich Islands'],
9089
['value' => 'PM', 'label' => 'Saint Pierre and Miquelon'],
9190
];
@@ -118,7 +117,6 @@ public function testGetOptionTimezones()
118117
['value' => 'America/Los_Angeles', 'label' => 'Pacific Standard Time (America/Los_Angeles)'],
119118
['value' => 'Europe/Kiev', 'label' => 'Eastern European Standard Time (Europe/Kiev)'],
120119
['value' => 'Asia/Jerusalem', 'label' => 'Israel Standard Time (Asia/Jerusalem)'],
121-
['value' => 'Asia/Yakutsk', 'label' => 'Yakutsk Standard Time (Asia/Yakutsk)'],
122120
];
123121

124122
$timeZones = $this->listsModel->getOptionTimezones();
@@ -138,7 +136,6 @@ public function testGetOptionLocales()
138136

139137
$this->assertEquals(
140138
[
141-
['value' => 'az_Latn_AZ', 'label' => 'Azerbaijani (Azerbaijan)'],
142139
['value' => 'en_US', 'label' => 'English (United States)'],
143140
['value' => 'uk_UA', 'label' => 'Ukrainian (Ukraine)'],
144141
],
@@ -152,7 +149,6 @@ public function testGetTranslatedOptionLocales()
152149

153150
$this->assertEquals(
154151
[
155-
['value' => 'az_Latn_AZ', 'label' => 'Azərbaycan (Azərbaycan) / Azerbaijani (Azerbaijan)'],
156152
['value' => 'en_US', 'label' => 'English (United States) / English (United States)'],
157153
['value' => 'uk_UA', 'label' => 'українська (Україна) / Ukrainian (Ukraine)'],
158154
],
@@ -165,7 +161,7 @@ public function testGetTranslatedOptionLocales()
165161
*/
166162
protected function setupForOptionLocales()
167163
{
168-
$allowedLocales = ['en_US', 'az_Latn_AZ', 'uk_UA'];
164+
$allowedLocales = ['en_US', 'uk_UA'];
169165
$this->mockConfig->expects($this->once())
170166
->method('getAllowedLocales')
171167
->will($this->returnValue($allowedLocales));

dev/tests/unit/testsuite/Magento/Setup/Model/ListsTest.php

Lines changed: 16 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -24,77 +24,30 @@ class ListsTest extends \PHPUnit_Framework_TestCase
2424
* @var array
2525
*/
2626
protected $expectedTimezones = [
27-
'Australia/Darwin' => 'Australian Central Standard Time (Australia/Darwin)',
28-
'America/Los_Angeles' => 'Pacific Standard Time (America/Los_Angeles)',
29-
'Europe/Kiev' => 'Eastern European Standard Time (Europe/Kiev)',
30-
'Asia/Jerusalem' => 'Israel Standard Time (Asia/Jerusalem)',
31-
'Asia/Yakutsk' => 'Yakutsk Standard Time (Asia/Yakutsk)',
27+
'Australia/Darwin',
28+
'America/Los_Angeles',
29+
'Europe/Kiev',
30+
'Asia/Jerusalem',
3231
];
3332

3433
/**
3534
* @var array
3635
*/
3736
protected $expectedCurrencies = [
38-
'XUA' => 'ADB Unit of Account (XUA)',
39-
'AFA' => 'Afghan Afghani (1927–2002) (AFA)',
40-
'AZM' => 'Azerbaijani Manat (1993–2006) (AZM)',
41-
'AZN' => 'Azerbaijani Manat (AZN)',
42-
'BOB' => 'Bolivian Boliviano (BOB)',
43-
'CUC' => 'Cuban Convertible Peso (CUC)',
44-
'CUP' => 'Cuban Peso (CUP)',
45-
'CYP' => 'Cypriot Pound (CYP)',
46-
'CZK' => 'Czech Republic Koruna (CZK)',
47-
'CSK' => 'Czechoslovak Hard Koruna (CSK)',
48-
'DKK' => 'Danish Krone (DKK)',
49-
'ZRN' => 'Zairean New Zaire (1993–1998) (ZRN)',
50-
'ZRZ' => 'Zairean Zaire (1971–1993) (ZRZ)',
51-
'ZMK' => 'Zambian Kwacha (1968–2012) (ZMK)',
52-
'ZMW' => 'Zambian Kwacha (ZMW)',
53-
'ZWD' => 'Zimbabwean Dollar (1980–2008) (ZWD)',
37+
'USD',
38+
'EUR',
39+
'UAH',
40+
'GBP',
5441
];
5542

5643
/**
5744
* @var array
5845
*/
5946
protected $expectedLocales = [
60-
'ar_DJ' => 'Arabic (Djibouti)',
61-
'ar_ER' => 'Arabic (Eritrea)',
62-
'ar_TN' => 'Arabic (Tunisia)',
63-
'bn_BD' => 'Bengali (Bangladesh)',
64-
'bn_IN' => 'Bengali (India)',
65-
'brx_IN' => 'Bodo (India)',
66-
'zh_Hans_CN' => 'Chinese (China)',
67-
'zh_Hant_HK' => 'Chinese (Hong Kong SAR China)',
68-
'nl_NL' => 'Dutch (Netherlands)',
69-
'nl_SX' => 'Dutch (Sint Maarten)',
70-
'en_BW' => 'English (Botswana)',
71-
'fr_BJ' => 'French (Benin)',
72-
'fr_BF' => 'French (Burkina Faso)',
73-
'ga_IE' => 'Irish (Ireland)',
74-
'it_IT' => 'Italian (Italy)',
75-
'lag_TZ' => 'Langi (Tanzania)',
76-
'lo_LA' => 'Lao (Laos)',
77-
'lv_LV' => 'Latvian (Latvia)',
78-
'ln_AO' => 'Lingala (Angola)',
79-
'pt_TL' => 'Portuguese (Timor-Leste)',
80-
'ro_MD' => 'Romanian (Moldova)',
81-
'ro_RO' => 'Romanian (Romania)',
82-
'rm_CH' => 'Romansh (Switzerland)',
83-
'rof_TZ' => 'Rombo (Tanzania)',
84-
'rn_BI' => 'Rundi (Burundi)',
85-
'ru_UA' => 'Russian (Ukraine)',
86-
'rwk_TZ' => 'Rwa (Tanzania)',
87-
'so_ET' => 'Somali (Ethiopia)',
88-
'es_ES' => 'Spanish (Spain)',
89-
'es_US' => 'Spanish (United States)',
90-
'teo_UG' => 'Teso (Uganda)',
91-
'th_TH' => 'Thai (Thailand)',
92-
'bo_CN' => 'Tibetan (China)',
93-
'yav_CM' => 'Yangben (Cameroon)',
94-
'yo_BJ' => 'Yoruba (Benin)',
95-
'yo_NG' => 'Yoruba (Nigeria)',
96-
'dje_NE' => 'Zarma (Niger)',
97-
'zu_ZA' => 'Zulu (South Africa)',
47+
'en_US',
48+
'en_GB',
49+
'uk_UA',
50+
'de_DE',
9851
];
9952

10053
public function setUp()
@@ -104,26 +57,26 @@ public function setUp()
10457
->getMock();
10558
$this->mockConfig->expects($this->any())
10659
->method('getAllowedLocales')
107-
->willReturn(array_keys($this->expectedLocales));
60+
->willReturn($this->expectedLocales);
10861

10962
$this->lists = new Lists($this->mockConfig);
11063
}
11164

11265
public function testGetTimezoneList()
11366
{
114-
$timezones = array_intersect_assoc($this->expectedTimezones, $this->lists->getTimezoneList());
67+
$timezones = array_intersect($this->expectedTimezones, array_keys($this->lists->getTimezoneList()));
11568
$this->assertEquals($this->expectedTimezones, $timezones);
11669
}
11770

11871
public function testGetCurrencyList()
11972
{
120-
$currencies = array_intersect_assoc($this->expectedCurrencies, $this->lists->getCurrencyList());
73+
$currencies = array_intersect($this->expectedCurrencies, array_keys($this->lists->getCurrencyList()));
12174
$this->assertEquals($this->expectedCurrencies, $currencies);
12275
}
12376

12477
public function testGetLocaleList()
12578
{
126-
$locales = array_intersect_assoc($this->expectedLocales, $this->lists->getLocaleList());
79+
$locales = array_intersect($this->expectedLocales, array_keys($this->lists->getLocaleList()));
12780
$this->assertEquals($this->expectedLocales, $locales);
12881
}
12982
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Locale\Bundle;
7+
8+
class CurrencyBundle extends DataBundle
9+
{
10+
protected $path = 'ICUDATA-curr';
11+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Locale\Bundle;
7+
8+
class DataBundle
9+
{
10+
/**
11+
* @var string
12+
*/
13+
protected $path = 'ICUDATA';
14+
15+
/**
16+
* @var \ResourceBundle[][]
17+
*/
18+
protected static $bundles = [];
19+
20+
/**
21+
* Get resource bundle for the locale
22+
*
23+
* @param string $locale
24+
* @return \ResourceBundle
25+
*/
26+
public function get($locale)
27+
{
28+
$class = get_class($this);
29+
if (!isset(static::$bundles[$class][$locale])) {
30+
$bundle = new \ResourceBundle($locale, $this->path);
31+
if ($bundle->count() == 0 && $this->path != 'ICUDATA') {
32+
$bundle = new \ResourceBundle($locale, 'ICUDATA');
33+
}
34+
static::$bundles[$class][$locale] = $bundle;
35+
}
36+
return static::$bundles[$class][$locale];
37+
}
38+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Locale\Bundle;
7+
8+
class LanguageBundle extends DataBundle
9+
{
10+
protected $path = 'ICUDATA-lang';
11+
}

0 commit comments

Comments
 (0)