Skip to content

Commit

Permalink
MAGETWO-34389: Implement Zend locale interface in Magento\Locale usin…
Browse files Browse the repository at this point in the history
…g PHP Intl extention
  • Loading branch information
slavvka committed Feb 26, 2015
1 parent ba82edc commit c292789
Show file tree
Hide file tree
Showing 86 changed files with 598 additions and 1,241 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/App/AbstractAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ protected function _processLocaleSettings()
}

if (is_null($this->_getSession()->getLocale())) {
$this->_getSession()->setLocale($this->_localeResolver->getLocaleCode());
$this->_getSession()->setLocale($this->_localeResolver->getLocale());
}

return $this;
Expand Down
13 changes: 1 addition & 12 deletions app/code/Magento/Backend/Block/Dashboard/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,19 @@ class Graph extends \Magento\Backend\Block\Dashboard\AbstractDashboard
*/
protected $_dashboardData = null;

/**
* @var \Magento\Framework\Locale\ListsInterface
*/
protected $_localeLists = null;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Reports\Model\Resource\Order\CollectionFactory $collectionFactory
* @param \Magento\Backend\Helper\Dashboard\Data $dashboardData
* @param \Magento\Framework\Locale\ListsInterface $localeLists
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Reports\Model\Resource\Order\CollectionFactory $collectionFactory,
\Magento\Backend\Helper\Dashboard\Data $dashboardData,
\Magento\Framework\Locale\ListsInterface $localeLists,
array $data = []
) {
$this->_dashboardData = $dashboardData;
$this->_localeLists = $localeLists;
parent::__construct($context, $collectionFactory, $data);
}

Expand Down Expand Up @@ -409,10 +401,7 @@ public function getChartUrl($directUrl = true)
break;
case '1y':
case '2y':
$formats = $this->_localeLists->getTranslationList('datetime');
$format = isset($formats['yyMM']) ? $formats['yyMM'] : 'MM/yyyy';
$format = str_replace(["yyyy", "yy", "MM"], ["Y", "y", "m"], $format);
$this->_axisLabels[$idx][$_index] = date($format, strtotime($_label));
$this->_axisLabels[$idx][$_index] = date('m/Y', strtotime($_label));
break;
}
} else {
Expand Down
4 changes: 1 addition & 3 deletions app/code/Magento/Backend/Block/Dashboard/Tab/Amounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,18 @@ class Amounts extends \Magento\Backend\Block\Dashboard\Graph
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Reports\Model\Resource\Order\CollectionFactory $collectionFactory
* @param \Magento\Backend\Helper\Dashboard\Data $dashboardData
* @param \Magento\Framework\Locale\ListsInterface $localeLists
* @param \Magento\Backend\Helper\Dashboard\Order $dataHelper
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Reports\Model\Resource\Order\CollectionFactory $collectionFactory,
\Magento\Backend\Helper\Dashboard\Data $dashboardData,
\Magento\Framework\Locale\ListsInterface $localeLists,
\Magento\Backend\Helper\Dashboard\Order $dataHelper,
array $data = []
) {
$this->_dataHelper = $dataHelper;
parent::__construct($context, $collectionFactory, $dashboardData, $localeLists, $data);
parent::__construct($context, $collectionFactory, $dashboardData, $data);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions app/code/Magento/Backend/Block/Dashboard/Tab/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,18 @@ class Orders extends \Magento\Backend\Block\Dashboard\Graph
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Reports\Model\Resource\Order\CollectionFactory $collectionFactory
* @param \Magento\Backend\Helper\Dashboard\Data $dashboardData
* @param \Magento\Framework\Locale\ListsInterface $localeLists
* @param \Magento\Backend\Helper\Dashboard\Order $dataHelper
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Reports\Model\Resource\Order\CollectionFactory $collectionFactory,
\Magento\Backend\Helper\Dashboard\Data $dashboardData,
\Magento\Framework\Locale\ListsInterface $localeLists,
\Magento\Backend\Helper\Dashboard\Order $dataHelper,
array $data = []
) {
$this->_dataHelper = $dataHelper;
parent::__construct($context, $collectionFactory, $dashboardData, $localeLists, $data);
parent::__construct($context, $collectionFactory, $dashboardData, $data);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/Block/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public function getCacheKeyInfo()
'admin_top_nav',
$this->getActive(),
$this->_authSession->getUser()->getId(),
$this->_localeResolver->getLocaleCode(),
$this->_localeResolver->getLocale(),
];
// Add additional key parameters if needed
$newCacheKeyInfo = $this->getAdditionalCacheKeyInfo();
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/Block/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function _construct()
public function getLang()
{
if (!$this->hasData('lang')) {
$this->setData('lang', substr($this->_localeResolver->getLocaleCode(), 0, 2));
$this->setData('lang', substr($this->_localeResolver->getLocale(), 0, 2));
}
return $this->getData('lang');
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/Block/Page/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function getLocaleSelect()
->setId('footer_interface_locale')
->setTitle(__('Interface Language'))
->setClass('select locale-switcher-select')
->setValue($this->_localeResolver->getLocale()->__toString())
->setValue($this->_localeResolver->getLocale())
->setOptions($this->_localeLists->getTranslatedOptionLocales())
->getHtml();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function getHtml()
$this->_getHtmlName() .
'[locale]"' .
' value="' .
$this->_localeResolver->getLocaleCode() .
$this->_localeResolver->getLocale() .
'"/>';
$html .= '<script>
require(["jquery", "mage/calendar"], function($){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function getHtml()
'to'
) . '/>' . '</div></div>';
$html .= '<input type="hidden" name="' . $this->_getHtmlName() . '[locale]"' . ' value="'
. $this->_localeResolver->getLocaleCode() . '"/>';
. $this->_localeResolver->getLocale() . '"/>';
$html .= '<script>
require(["jquery", "mage/calendar"],function($){
$("#' . $htmlId . '_range").dateRange({
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function setPageHelpUrl($url = null)
}
}
$url = 'http://www.magentocommerce.com/gethelp/';
$url .= $this->_locale->getLocaleCode() . '/';
$url .= $this->_locale->getLocale() . '/';
$url .= $frontModule . '/';
$url .= $request->getControllerName() . '/';
$url .= $request->getActionName() . '/';
Expand Down
12 changes: 3 additions & 9 deletions app/code/Magento/Backend/Model/Locale/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ class Resolver extends \Magento\Framework\Locale\Resolver

/**
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Framework\App\CacheInterface $cache
* @param \Magento\Framework\LocaleFactory $localeFactory
* @param string $defaultLocalePath
* @param string $scopeType
* @param \Magento\Backend\Model\Session $session
Expand All @@ -45,8 +43,6 @@ class Resolver extends \Magento\Framework\Locale\Resolver
*/
public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Framework\App\CacheInterface $cache,
\Magento\Framework\LocaleFactory $localeFactory,
$defaultLocalePath,
$scopeType,
\Magento\Backend\Model\Session $session,
Expand All @@ -59,7 +55,7 @@ public function __construct(
$this->_localeManager = $localeManager;
$this->_request = $request;
$this->_localeValidator = $localeValidator;
parent::__construct($scopeConfig, $cache, $localeFactory, $defaultLocalePath, $scopeType, $locale);
parent::__construct($scopeConfig, $defaultLocalePath, $scopeType, $locale);
}

/**
Expand All @@ -70,8 +66,6 @@ public function __construct(
*/
public function setLocale($locale = null)
{
parent::setLocale($locale);

$forceLocale = $this->_request->getParam('locale', null);
if (!$this->_localeValidator->isValid($forceLocale)) {
$forceLocale = false;
Expand All @@ -83,9 +77,9 @@ public function setLocale($locale = null)
$localeCodes = array_filter([$forceLocale, $sessionLocale, $userLocale]);

if (count($localeCodes)) {
$this->setLocaleCode(reset($localeCodes));
$locale = reset($localeCodes);
}

return $this;
return parent::setLocale($locale);
}
}
28 changes: 0 additions & 28 deletions app/code/Magento/Backend/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,20 @@
*/
class Observer
{
/**
* @var \Magento\Backend\Model\Session
*/
protected $backendSession;

/**
* @var \Magento\Framework\App\Cache\Frontend\Pool
*/
private $cacheFrontendPool;

/**
* Initialize dependencies
*
* @param Session $backendSession
* @param \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool
*/
public function __construct(
\Magento\Backend\Model\Session $backendSession,
\Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool
) {
$this->backendSession = $backendSession;
$this->cacheFrontendPool = $cacheFrontendPool;
}

/**
* Bind locale
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function bindLocale($observer)
{
$locale = $observer->getEvent()->getLocale();
if ($locale) {
$selectedLocale = $this->backendSession->getLocale();
if ($selectedLocale) {
$locale->setLocaleCode($selectedLocale);
}
}
return $this;
}

/**
* Clear result of configuration files access level verification in system cache
*
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backup/Model/Backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function load($fileName, $filePath)
'name' => $backupData->getName(),
'date_object' => new \Magento\Framework\Stdlib\DateTime\Date(
(int)$backupData->getTime(),
$this->_localeResolver->getLocaleCode()
$this->_localeResolver->getLocale()
),
]
);
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Block/Rss/Product/Special.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ protected function getEntryData(\Magento\Catalog\Model\Product $item)
[
'date' => $item->getSpecialToDate(),
'part' => \Magento\Framework\Stdlib\DateTime\Date::ISO_8601,
'locale' => $this->localeResolver->getLocaleCode()
'locale' => $this->localeResolver->getLocale()
]
),
\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class Full
/**
* @var \Magento\Framework\Search\Request\Config
*/
private $searchRequestConfig;
protected $searchRequestConfig;

/**
* @param \Magento\Framework\App\Resource $resource
Expand Down Expand Up @@ -768,16 +768,18 @@ protected function getStoreDate($storeId, $date = null)
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$storeId
);
$locale = $this->scopeConfig->getValue(
$this->localeResolver->getDefaultLocalePath(),
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$storeId
);
$locale = new \Zend_Locale($locale);

$locale = $this->localeResolver->emulate($storeId);

$dateObj = new \Magento\Framework\Stdlib\DateTime\Date(null, null, $locale);
$dateObj->setTimezone($timezone);
$this->dates[$storeId] = [$dateObj, $locale->getTranslation(null, 'date', $locale)];
$format = (new \ResourceBundle(
$this->localeResolver->getLocale(),
'ICUDATA'
))['calendar']['gregorian']['availableFormats']['yMMMd'];
$this->dates[$storeId] = [$dateObj, $format];

$this->localeResolver->revert();
}

if (!$this->dateTime->isEmptyDate($date)) {
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Checkout/Controller/Cart/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function execute()
try {
if (isset($params['qty'])) {
$filter = new \Zend_Filter_LocalizedToNormalized(
['locale' => $this->_objectManager->get('Magento\Framework\Locale\ResolverInterface')->getLocaleCode()]
['locale' => $this->_objectManager->get('Magento\Framework\Locale\ResolverInterface')->getLocale()]
);
$params['qty'] = $filter->filter($params['qty']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function execute()
try {
if (isset($params['qty'])) {
$filter = new \Zend_Filter_LocalizedToNormalized(
['locale' => $this->_objectManager->get('Magento\Framework\Locale\ResolverInterface')->getLocaleCode()]
['locale' => $this->_objectManager->get('Magento\Framework\Locale\ResolverInterface')->getLocale()]
);
$params['qty'] = $filter->filter($params['qty']);
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Checkout/Controller/Cart/UpdatePost.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function _updateShoppingCart()
$cartData = $this->getRequest()->getParam('cart');
if (is_array($cartData)) {
$filter = new \Zend_Filter_LocalizedToNormalized(
['locale' => $this->_objectManager->get('Magento\Framework\Locale\ResolverInterface')->getLocaleCode()]
['locale' => $this->_objectManager->get('Magento\Framework\Locale\ResolverInterface')->getLocale()]
);
foreach ($cartData as $index => $data) {
if (isset($data['qty'])) {
Expand Down
16 changes: 6 additions & 10 deletions app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ class Currencysymbol
protected $_storeManager;

/**
* @var \Magento\Framework\LocaleInterface
* @var \Magento\Framework\Locale\ResolverInterface
*/
protected $_locale;
protected $localeResolver;

/**
* @var \Magento\Framework\App\Config\ReinitableConfigInterface
Expand Down Expand Up @@ -129,7 +129,7 @@ public function __construct(
$this->_configFactory = $configFactory;
$this->_cacheTypeList = $cacheTypeList;
$this->_storeManager = $storeManager;
$this->_locale = $localeResolver->getLocale();
$this->localeResolver = $localeResolver;
$this->_systemStore = $systemStore;
$this->_eventManager = $eventManager;
$this->_scopeConfig = $scopeConfig;
Expand Down Expand Up @@ -196,13 +196,9 @@ public function getCurrencySymbolsData()
$currentSymbols = $this->_unserializeStoreConfig(self::XML_PATH_CUSTOM_CURRENCY_SYMBOL);

foreach ($allowedCurrencies as $code) {
if (!($symbol = $this->_locale->getTranslation($code, 'currencysymbol'))) {
$symbol = $code;
}
$name = $this->_locale->getTranslation($code, 'nametocurrency');
if (!$name) {
$name = $code;
}
$currencies = (new \ResourceBundle($this->localeResolver->getLocale(), 'ICUDATA-curr'))['Currencies'];
$symbol = $currencies[$code][0] ?: $code;
$name = $currencies[$code][1] ?: $code;
$this->_symbolsData[$code] = ['parentSymbol' => $symbol, 'displayName' => $name];

if (isset($currentSymbols[$code]) && !empty($currentSymbols[$code])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ protected function _getFormFilter()
if ($filterCode) {
$filterClass = 'Magento\Framework\Data\Form\Filter\\' . ucfirst($filterCode);
if ($filterCode == 'date') {
$filter = new $filterClass($this->_dateFilterFormat(), $this->_localeResolver->getLocale());
$filter = new $filterClass($this->_dateFilterFormat(), $this->_localeResolver);
} else {
$filter = new $filterClass();
}
Expand Down
Loading

0 comments on commit c292789

Please sign in to comment.