/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
lib/internal/Magento/Framework/Locale/Bundle/DataBundle.php
74 строки
2 KB
Alexandra Zota
ACP2E-4019: CE copyright updates for 2.4.9-beta1
22 окт 2025, 17:47
22 окт 2025, 17:47
1b769b7
Код
Авторство
О чём код?
<?php /** * Copyright 2015 Adobe * All Rights Reserved. */ namespace Magento\Framework\Locale\Bundle; class DataBundle { /** * @var string */ protected $path = 'ICUDATA'; /** * @var \ResourceBundle[][] */ protected static $bundles = []; /** * Get resource bundle for the locale * * @param string $locale * @return \ResourceBundle */ public function get($locale) { $locale = $this->cleanLocale($locale); $class = get_class($this); if (!isset(static::$bundles[$class][$locale])) { $bundle = $this->createResourceBundle($locale, $this->path); if (!$bundle && $this->path != 'ICUDATA') { $bundle = $this->createResourceBundle($locale, 'ICUDATA'); } static::$bundles[$class][$locale] = $bundle; } return static::$bundles[$class][$locale]; } /** * @param string $locale * @param string $path * @return null|\ResourceBundle */ protected function createResourceBundle($locale, $path) { try { $bundle = new \ResourceBundle($locale, $path); } catch (\Exception $e) { // HHVM compatibility: constructor throws on invalid resource $bundle = null; } return $bundle; } /** * Clean locale leaving only language and script * * @param string $locale * @return string */ protected function cleanLocale($locale) { $localeParts = \Locale::parseLocale($locale); $cleanLocaleParts = []; if (isset($localeParts['language'])) { $cleanLocaleParts['language'] = $localeParts['language']; } if (isset($localeParts['script'])) { $cleanLocaleParts['script'] = $localeParts['script']; } return \Locale::composeLocale($cleanLocaleParts); } }