[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:
Eriksen Costa 2012-08-05 21:38:44 -03:00
parent 3f2b4bf344
commit d909360942
6 changed files with 40 additions and 54 deletions

View File

@ -8,4 +8,5 @@ php:
before_script:
- curl -s http://getcomposer.org/installer | php
- 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

View File

@ -13,6 +13,11 @@ namespace Symfony\Component\Locale;
class Locale extends \Locale
{
/**
* The ICU data version that ships with Symfony
*/
const ICU_DATA_VERSION = '49';
/**
* Caches the countries in different locales
* @var array
@ -43,7 +48,7 @@ class Locale extends \Locale
public static function getDisplayCountries($locale)
{
if (!isset(self::$countries[$locale])) {
$bundle = \ResourceBundle::create($locale, self::getDataDirectory().'/region');
$bundle = \ResourceBundle::create($locale, self::getIcuDataDirectory().'/region');
if (null === $bundle) {
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)
{
if (!isset(self::$languages[$locale])) {
$bundle = \ResourceBundle::create($locale, self::getDataDirectory().'/lang');
$bundle = \ResourceBundle::create($locale, self::getIcuDataDirectory().'/lang');
if (null === $bundle) {
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)
{
if (!isset(self::$locales[$locale])) {
$bundle = \ResourceBundle::create($locale, self::getDataDirectory().'/names');
$bundle = \ResourceBundle::create($locale, self::getIcuDataDirectory().'/names');
if (null === $bundle) {
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
*/
public static function getIcuVersion()
public static function getIntlIcuVersion()
{
if (defined('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
*/
public static function getIcuDataVersion()
public static function getIntlIcuDataVersion()
{
if (defined('INTL_ICU_DATA_VERSION')) {
return INTL_ICU_DATA_VERSION;
@ -237,26 +242,39 @@ class Locale extends \Locale
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;
if (null === $dataVersion) {
$dataVersion = 'current';
$dataVersion = self::ICU_DATA_VERSION;
if (getenv('ICU_DATA_VERSION')) {
$dataVersion = getenv('ICU_DATA_VERSION');
} elseif (file_exists(__DIR__.'/../Resources/data/data-version.php')) {
$dataVersion = include __DIR__.'/../Resources/data/data-version.php';
if (getenv('USE_INTL_ICU_DATA_VERSION') && self::getIntlIcuVersion()) {
$dataVersion = self::getIntlIcuVersion();
preg_match('/^(?P<version>[0-9]\.[0-9]|[0-9]{2,})/', $dataVersion, $matches);
$dataVersion = $matches['version'];
}
}
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();
}
/**

View File

@ -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.
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
to a major version, add a new version key, the SVN URL and update the
`latest version` with the new version key. For each major ICU release, try to
use the latest release tag available.
a newer version, just update the SVN URL for the desired release URL. 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
`icu-config` ICU binaries.

View File

@ -164,17 +164,6 @@ function is_42_or_earlier($version)
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)
{
$template = <<<TEMPLATE
@ -291,7 +280,7 @@ if (!is_42_or_earlier($version)) {
check_dir($source.DIRECTORY_SEPARATOR.'locales');
// Convert the *.txt resource bundles to *.res files
$target = is_latest_version($version) ? 'current' : $version;
$target = $version;
$target = __DIR__.DIRECTORY_SEPARATOR.$target;
$currDir = $target.DIRECTORY_SEPARATOR.'curr';
$langDir = $target.DIRECTORY_SEPARATOR.'lang';
@ -636,20 +625,4 @@ create_stub_datafile($defaultLocale, $stubRegionDir, $countries);
// Clean up
clear_directory($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);
}
rmdir($currDir);

View File

@ -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
; 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

View File

@ -498,7 +498,7 @@ class StubLocale
*/
private static function getStubData($locale, $cacheVariable, $stubDataDir)
{
$dataDirectory = Locale::getDataDirectory();
$dataDirectory = Locale::getIcuDataDirectory();
if ('en' !== $locale) {
throw new \InvalidArgumentException(sprintf('Only the \'en\' locale is supported. %s', NotImplementedException::INTL_INSTALL_MESSAGE));