[Locale] don't create a "current" directory anymore, uses only the ICU version as the name of the data directory
This commit is contained in:
parent
3f2b4bf344
commit
d909360942
@ -9,3 +9,4 @@ before_script:
|
|||||||
- curl -s http://getcomposer.org/installer | php
|
- curl -s http://getcomposer.org/installer | php
|
||||||
- COMPOSER_ROOT_VERSION=dev-master php composer.phar --dev install
|
- COMPOSER_ROOT_VERSION=dev-master php composer.phar --dev install
|
||||||
- php src/Symfony/Component/Locale/Resources/data/build-data.php
|
- php src/Symfony/Component/Locale/Resources/data/build-data.php
|
||||||
|
- export USE_INTL_ICU_DATA_VERSION=1
|
@ -13,6 +13,11 @@ namespace Symfony\Component\Locale;
|
|||||||
|
|
||||||
class Locale extends \Locale
|
class Locale extends \Locale
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* The ICU data version that ships with Symfony
|
||||||
|
*/
|
||||||
|
const ICU_DATA_VERSION = '49';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caches the countries in different locales
|
* Caches the countries in different locales
|
||||||
* @var array
|
* @var array
|
||||||
@ -43,7 +48,7 @@ class Locale extends \Locale
|
|||||||
public static function getDisplayCountries($locale)
|
public static function getDisplayCountries($locale)
|
||||||
{
|
{
|
||||||
if (!isset(self::$countries[$locale])) {
|
if (!isset(self::$countries[$locale])) {
|
||||||
$bundle = \ResourceBundle::create($locale, self::getDataDirectory().'/region');
|
$bundle = \ResourceBundle::create($locale, self::getIcuDataDirectory().'/region');
|
||||||
|
|
||||||
if (null === $bundle) {
|
if (null === $bundle) {
|
||||||
throw new \RuntimeException(sprintf('The country resource bundle could not be loaded for locale "%s"', $locale));
|
throw new \RuntimeException(sprintf('The country resource bundle could not be loaded for locale "%s"', $locale));
|
||||||
@ -98,7 +103,7 @@ class Locale extends \Locale
|
|||||||
public static function getDisplayLanguages($locale)
|
public static function getDisplayLanguages($locale)
|
||||||
{
|
{
|
||||||
if (!isset(self::$languages[$locale])) {
|
if (!isset(self::$languages[$locale])) {
|
||||||
$bundle = \ResourceBundle::create($locale, self::getDataDirectory().'/lang');
|
$bundle = \ResourceBundle::create($locale, self::getIcuDataDirectory().'/lang');
|
||||||
|
|
||||||
if (null === $bundle) {
|
if (null === $bundle) {
|
||||||
throw new \RuntimeException(sprintf('The language resource bundle could not be loaded for locale "%s"', $locale));
|
throw new \RuntimeException(sprintf('The language resource bundle could not be loaded for locale "%s"', $locale));
|
||||||
@ -149,7 +154,7 @@ class Locale extends \Locale
|
|||||||
public static function getDisplayLocales($locale)
|
public static function getDisplayLocales($locale)
|
||||||
{
|
{
|
||||||
if (!isset(self::$locales[$locale])) {
|
if (!isset(self::$locales[$locale])) {
|
||||||
$bundle = \ResourceBundle::create($locale, self::getDataDirectory().'/names');
|
$bundle = \ResourceBundle::create($locale, self::getIcuDataDirectory().'/names');
|
||||||
|
|
||||||
if (null === $bundle) {
|
if (null === $bundle) {
|
||||||
throw new \RuntimeException(sprintf('The locale resource bundle could not be loaded for locale "%s"', $locale));
|
throw new \RuntimeException(sprintf('The locale resource bundle could not be loaded for locale "%s"', $locale));
|
||||||
@ -188,11 +193,11 @@ class Locale extends \Locale
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the ICU version
|
* Returns the ICU version as defined by the intl extension
|
||||||
*
|
*
|
||||||
* @return string|null The ICU version
|
* @return string|null The ICU version
|
||||||
*/
|
*/
|
||||||
public static function getIcuVersion()
|
public static function getIntlIcuVersion()
|
||||||
{
|
{
|
||||||
if (defined('INTL_ICU_VERSION')) {
|
if (defined('INTL_ICU_VERSION')) {
|
||||||
return INTL_ICU_VERSION;
|
return INTL_ICU_VERSION;
|
||||||
@ -213,11 +218,11 @@ class Locale extends \Locale
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the ICU Data version
|
* Returns the ICU Data version as defined by the intl extension
|
||||||
*
|
*
|
||||||
* @return string|null The ICU Data version
|
* @return string|null The ICU Data version
|
||||||
*/
|
*/
|
||||||
public static function getIcuDataVersion()
|
public static function getIntlIcuDataVersion()
|
||||||
{
|
{
|
||||||
if (defined('INTL_ICU_DATA_VERSION')) {
|
if (defined('INTL_ICU_DATA_VERSION')) {
|
||||||
return INTL_ICU_DATA_VERSION;
|
return INTL_ICU_DATA_VERSION;
|
||||||
@ -237,26 +242,39 @@ class Locale extends \Locale
|
|||||||
return trim($matches[1]);
|
return trim($matches[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getDataVersion()
|
/**
|
||||||
|
* Returns the ICU data version that ships with Symfony. If the environment variable USE_INTL_ICU_DATA_VERSION is
|
||||||
|
* defined, it will try use the ICU data version as defined by the intl extension, if available.
|
||||||
|
*
|
||||||
|
* @return string The ICU data version that ships with Symfony
|
||||||
|
*/
|
||||||
|
public static function getIcuDataVersion()
|
||||||
{
|
{
|
||||||
static $dataVersion;
|
static $dataVersion;
|
||||||
|
|
||||||
if (null === $dataVersion) {
|
if (null === $dataVersion) {
|
||||||
$dataVersion = 'current';
|
$dataVersion = self::ICU_DATA_VERSION;
|
||||||
|
|
||||||
if (getenv('ICU_DATA_VERSION')) {
|
if (getenv('USE_INTL_ICU_DATA_VERSION') && self::getIntlIcuVersion()) {
|
||||||
$dataVersion = getenv('ICU_DATA_VERSION');
|
$dataVersion = self::getIntlIcuVersion();
|
||||||
} elseif (file_exists(__DIR__.'/../Resources/data/data-version.php')) {
|
|
||||||
$dataVersion = include __DIR__.'/../Resources/data/data-version.php';
|
preg_match('/^(?P<version>[0-9]\.[0-9]|[0-9]{2,})/', $dataVersion, $matches);
|
||||||
|
|
||||||
|
$dataVersion = $matches['version'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $dataVersion;
|
return $dataVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getDataDirectory()
|
/**
|
||||||
|
* Returns the directory path of the ICU data that ships with Symfony
|
||||||
|
*
|
||||||
|
* @return string The path to the ICU data directory
|
||||||
|
*/
|
||||||
|
public static function getIcuDataDirectory()
|
||||||
{
|
{
|
||||||
return __DIR__.'/Resources/data/'.self::getDataVersion();
|
return __DIR__.'/Resources/data/'.self::getIcuDataVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,10 +14,8 @@ It is recommended to use the ICU binaries in the same version of the desired
|
|||||||
version to build the data files.
|
version to build the data files.
|
||||||
|
|
||||||
You can use one of the versions available in the `icu.ini` file. To update to
|
You can use one of the versions available in the `icu.ini` file. To update to
|
||||||
a newer version, just update the SVN URL for the desired release URL. To update
|
a newer version, just update the SVN URL for the desired release URL. For each
|
||||||
to a major version, add a new version key, the SVN URL and update the
|
major ICU release, try to use the latest release tag available.
|
||||||
`latest version` with the new version key. For each major ICU release, try to
|
|
||||||
use the latest release tag available.
|
|
||||||
|
|
||||||
The script requires `svn` (used to download the ICU data) and the `genrb` and
|
The script requires `svn` (used to download the ICU data) and the `genrb` and
|
||||||
`icu-config` ICU binaries.
|
`icu-config` ICU binaries.
|
||||||
|
@ -164,17 +164,6 @@ function is_42_or_earlier($version)
|
|||||||
return version_compare($version, '4.4', '<');
|
return version_compare($version, '4.4', '<');
|
||||||
}
|
}
|
||||||
|
|
||||||
function is_latest_version($version)
|
|
||||||
{
|
|
||||||
$icu = parse_ini_file(__DIR__.DIRECTORY_SEPARATOR.'icu.ini');
|
|
||||||
|
|
||||||
if (!isset($icu[$version])) {
|
|
||||||
bailout('The version '.$version.' is not available in the icu.ini file.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $icu['latest version'] == $version;
|
|
||||||
}
|
|
||||||
|
|
||||||
function create_stub_datafile($locale, $target, $data)
|
function create_stub_datafile($locale, $target, $data)
|
||||||
{
|
{
|
||||||
$template = <<<TEMPLATE
|
$template = <<<TEMPLATE
|
||||||
@ -291,7 +280,7 @@ if (!is_42_or_earlier($version)) {
|
|||||||
check_dir($source.DIRECTORY_SEPARATOR.'locales');
|
check_dir($source.DIRECTORY_SEPARATOR.'locales');
|
||||||
|
|
||||||
// Convert the *.txt resource bundles to *.res files
|
// Convert the *.txt resource bundles to *.res files
|
||||||
$target = is_latest_version($version) ? 'current' : $version;
|
$target = $version;
|
||||||
$target = __DIR__.DIRECTORY_SEPARATOR.$target;
|
$target = __DIR__.DIRECTORY_SEPARATOR.$target;
|
||||||
$currDir = $target.DIRECTORY_SEPARATOR.'curr';
|
$currDir = $target.DIRECTORY_SEPARATOR.'curr';
|
||||||
$langDir = $target.DIRECTORY_SEPARATOR.'lang';
|
$langDir = $target.DIRECTORY_SEPARATOR.'lang';
|
||||||
@ -637,19 +626,3 @@ create_stub_datafile($defaultLocale, $stubRegionDir, $countries);
|
|||||||
// Clean up
|
// Clean up
|
||||||
clear_directory($currDir);
|
clear_directory($currDir);
|
||||||
rmdir($currDir);
|
rmdir($currDir);
|
||||||
|
|
||||||
// Creates the data version file, used in CI environments
|
|
||||||
$dataVersion = __DIR__.DIRECTORY_SEPARATOR.'data-version.php';
|
|
||||||
|
|
||||||
if (!is_latest_version($version)) {
|
|
||||||
$data = <<<DATA_VERSION
|
|
||||||
<?php
|
|
||||||
|
|
||||||
return $version;
|
|
||||||
|
|
||||||
DATA_VERSION;
|
|
||||||
|
|
||||||
file_put_contents($dataVersion, $data);
|
|
||||||
} elseif (file_exists($dataVersion)) {
|
|
||||||
unlink($dataVersion);
|
|
||||||
}
|
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
; The latest ICU version
|
|
||||||
; It must be one of the available ICU SVN URLs key below.
|
|
||||||
latest version = 49
|
|
||||||
|
|
||||||
; ICU data source URLs
|
; ICU data source URLs
|
||||||
; We use always the latest release of a major version.
|
; We use always the latest release of a major version.
|
||||||
4.0 = http://source.icu-project.org/repos/icu/icu/tags/release-4-0-1/source/data
|
4.0 = http://source.icu-project.org/repos/icu/icu/tags/release-4-0-1/source/data
|
||||||
|
@ -498,7 +498,7 @@ class StubLocale
|
|||||||
*/
|
*/
|
||||||
private static function getStubData($locale, $cacheVariable, $stubDataDir)
|
private static function getStubData($locale, $cacheVariable, $stubDataDir)
|
||||||
{
|
{
|
||||||
$dataDirectory = Locale::getDataDirectory();
|
$dataDirectory = Locale::getIcuDataDirectory();
|
||||||
|
|
||||||
if ('en' !== $locale) {
|
if ('en' !== $locale) {
|
||||||
throw new \InvalidArgumentException(sprintf('Only the \'en\' locale is supported. %s', NotImplementedException::INTL_INSTALL_MESSAGE));
|
throw new \InvalidArgumentException(sprintf('Only the \'en\' locale is supported. %s', NotImplementedException::INTL_INSTALL_MESSAGE));
|
||||||
|
Reference in New Issue
Block a user