-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[WIP] added back ICU classes from symfony/Icu #11884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
added back ICU classes from symfony/Icu
- Loading branch information
commit 37b867221835f813f99c9a9493343b49ddc3c133
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Intl\Icu; | ||
|
||
use Symfony\Component\Intl\ResourceBundle\CurrencyBundle; | ||
use Symfony\Component\Intl\ResourceBundle\Reader\StructuredBundleReaderInterface; | ||
|
||
/** | ||
* An ICU-specific implementation of {@link \Symfony\Component\Intl\ResourceBundle\CurrencyBundleInterface}. | ||
* | ||
* This class normalizes the data of the ICU .res files to satisfy the contract | ||
* defined in {@link \Symfony\Component\Intl\ResourceBundle\CurrencyBundleInterface}. | ||
* | ||
* When no ICU resource files are available, this class acts as a stub implementation of | ||
* {@link \Symfony\Component\Intl\ResourceBundle\CurrencyBundleInterface}, only for the | ||
* English language. | ||
* | ||
* @author Bernhard Schussek <bschussek@gmail.com> | ||
*/ | ||
class IcuCurrencyBundle extends CurrencyBundle | ||
{ | ||
const INDEX_SYMBOL = 0; | ||
const INDEX_NAME = 1; | ||
const INDEX_FRACTION_DIGITS = 0; | ||
const INDEX_ROUNDING_INCREMENT = 1; | ||
|
||
private $stubbed; | ||
|
||
public function __construct(StructuredBundleReaderInterface $reader) | ||
{ | ||
$this->stubbed = IcuData::isStubbed(); | ||
|
||
parent::__construct(realpath(IcuData::getResourceDirectory().'/curr'), $reader); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getLocales() | ||
{ | ||
return $this->stubbed ? array('en') : $this->readEntry('misc', array('Locales')); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getCurrencyNames($locale = null) | ||
{ | ||
$names = parent::getCurrencyNames($locale); | ||
|
||
if ($this->stubbed) { | ||
return $names; | ||
} | ||
|
||
if (null === $locale) { | ||
$locale = \Locale::getDefault(); | ||
} | ||
|
||
$collator = new \Collator($locale); | ||
$collator->asort($names); | ||
|
||
return $names; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getFractionDigits($currency) | ||
{ | ||
if ($this->stubbed) { | ||
return parent::getFractionDigits($currency); | ||
} | ||
|
||
$entry = $this->readEntry('misc', array('CurrencyMeta')); | ||
|
||
if (!isset($entry[$currency][self::INDEX_FRACTION_DIGITS])) { | ||
// The 'DEFAULT' key contains the fraction digits and the rounding | ||
// increment that are common for a lot of currencies. | ||
// Only currencies with different values are added to the icu-data | ||
// (e.g: CHF and JPY) | ||
return $entry['DEFAULT'][self::INDEX_FRACTION_DIGITS]; | ||
} | ||
|
||
return $entry[$currency][self::INDEX_FRACTION_DIGITS]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getRoundingIncrement($currency) | ||
{ | ||
if ($this->stubbed) { | ||
return parent::getRoundingIncrement($currency); | ||
} | ||
|
||
$entry = $this->readEntry('misc', array('CurrencyMeta')); | ||
|
||
if (!isset($entry[$currency][self::INDEX_ROUNDING_INCREMENT])) { | ||
// The 'DEFAULT' key contains the fraction digits and the rounding | ||
// increment that are common for a lot of currencies. | ||
// Only currencies with different values are added to the icu-data | ||
// (e.g: CHF and JPY) | ||
return $entry['DEFAULT'][self::INDEX_ROUNDING_INCREMENT]; | ||
} | ||
|
||
return $entry[$currency][self::INDEX_ROUNDING_INCREMENT]; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Intl\Icu; | ||
|
||
use Symfony\Component\Intl\ResourceBundle\Reader\PhpBundleReader; | ||
|
||
/** | ||
* @author Bernhard Schussek <bschussek@gmail.com> | ||
*/ | ||
class IcuData | ||
{ | ||
/** | ||
* Returns the version of the bundled ICU data. | ||
* | ||
* @return string The version string. | ||
*/ | ||
public static function getVersion() | ||
{ | ||
return trim(file_get_contents(__DIR__.'/../Resources/data/version.txt')); | ||
} | ||
|
||
/** | ||
* Returns whether the ICU data is stubbed. | ||
* | ||
* @return Boolean Returns true if the ICU data is stubbed, false if it is | ||
* loaded from ICU .res files. | ||
*/ | ||
public static function isStubbed() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Returns the path to the directory where the resource bundles are stored. | ||
* | ||
* @return string The absolute path to the resource directory. | ||
*/ | ||
public static function getResourceDirectory() | ||
{ | ||
return realpath(__DIR__.'/../Resources/data'); | ||
} | ||
|
||
/** | ||
* Returns a reader for reading resource bundles in this component. | ||
* | ||
* @return \Symfony\Component\Intl\ResourceBundle\Reader\BundleReaderInterface | ||
*/ | ||
public static function getBundleReader() | ||
{ | ||
return new PhpBundleReader(); | ||
} | ||
|
||
/** | ||
* This class must not be instantiated. | ||
*/ | ||
private function __construct() | ||
{ | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Intl\Icu; | ||
|
||
use Symfony\Component\Intl\ResourceBundle\LanguageBundle; | ||
use Symfony\Component\Intl\ResourceBundle\Reader\StructuredBundleReaderInterface; | ||
|
||
/** | ||
* An ICU-specific implementation of {@link \Symfony\Component\Intl\ResourceBundle\LanguageBundleInterface}. | ||
* | ||
* This class normalizes the data of the ICU .res files to satisfy the contract | ||
* defined in {@link \Symfony\Component\Intl\ResourceBundle\LanguageBundleInterface}. | ||
* | ||
* @author Bernhard Schussek <bschussek@gmail.com> | ||
*/ | ||
class IcuLanguageBundle extends LanguageBundle | ||
{ | ||
private $stubbed; | ||
|
||
public function __construct(StructuredBundleReaderInterface $reader) | ||
{ | ||
$this->stubbed = IcuData::isStubbed(); | ||
|
||
parent::__construct(realpath(IcuData::getResourceDirectory().'/lang'), $reader); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getLocales() | ||
{ | ||
return $this->stubbed ? array('en') : $this->readEntry('misc', array('Locales')); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getLanguageName($lang, $region = null, $locale = null) | ||
{ | ||
if ('mul' === $lang) { | ||
return null; | ||
} | ||
|
||
return parent::getLanguageName($lang, $region, $locale); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getLanguageNames($locale = null) | ||
{ | ||
$languages = parent::getLanguageNames($locale); | ||
|
||
if ($this->stubbed) { | ||
return $languages; | ||
} | ||
|
||
if (null === $locale) { | ||
$locale = \Locale::getDefault(); | ||
} | ||
|
||
$collator = new \Collator($locale); | ||
$collator->asort($languages); | ||
|
||
// "mul" is the code for multiple languages | ||
unset($languages['mul']); | ||
|
||
return $languages; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getScriptNames($locale = null) | ||
{ | ||
if ($this->stubbed) { | ||
return parent::getScriptNames($locale); | ||
} | ||
|
||
if (null === $locale) { | ||
$locale = \Locale::getDefault(); | ||
} | ||
|
||
$scripts = parent::getScriptNames($locale); | ||
|
||
$collator = new \Collator($locale); | ||
$collator->asort($scripts); | ||
|
||
return $scripts; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Intl\Icu; | ||
|
||
use Symfony\Component\Intl\ResourceBundle\LocaleBundle; | ||
use Symfony\Component\Intl\ResourceBundle\Reader\StructuredBundleReaderInterface; | ||
|
||
/** | ||
* An ICU-specific implementation of {@link \Symfony\Component\Intl\ResourceBundle\LocaleBundleInterface}. | ||
* | ||
* This class normalizes the data of the ICU .res files to satisfy the contract | ||
* defined in {@link \Symfony\Component\Intl\ResourceBundle\LocaleBundleInterface}. | ||
* | ||
* @author Bernhard Schussek <bschussek@gmail.com> | ||
*/ | ||
class IcuLocaleBundle extends LocaleBundle | ||
{ | ||
private $stubbed; | ||
|
||
public function __construct(StructuredBundleReaderInterface 8E4B $reader) | ||
{ | ||
$this->stubbed = IcuData::isStubbed(); | ||
|
||
parent::__construct(realpath(IcuData::getResourceDirectory().'/locales'), $reader); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getLocales() | ||
{ | ||
return $this->stubbed ? array('en') : $this->readEntry('misc', array('Locales')); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getLocaleNames($locale = null) | ||
{ | ||
$locales = parent::getLocaleNames($locale); | ||
|
||
if ($this->stubbed) { | ||
return $locales; | ||
} | ||
|
||
if (null === $locale) { | ||
$locale = \Locale::getDefault(); | ||
} | ||
|
||
$collator = new \Collator($locale); | ||
$collator->asort($locales); | ||
|
||
return $locales; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is useless.
IcuData::isStubbed()
will always betrue
now, given there is a single version of the classThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah no, I missed the class_alias hack replacing the class defined here by the IntlData one. But I find this quite weird
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's weird. As we are going to remove the intl dep on IntlData, I will change this strategy.