diff --git a/.travis.yml b/.travis.yml index dc740465e8..53537d5f18 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 \ No newline at end of file + - php src/Symfony/Component/Locale/Resources/data/build-data.php + - export USE_INTL_ICU_DATA_VERSION=1 \ No newline at end of file diff --git a/src/Symfony/Component/Locale/Locale.php b/src/Symfony/Component/Locale/Locale.php index c1d00e8243..577f33fcd5 100644 --- a/src/Symfony/Component/Locale/Locale.php +++ b/src/Symfony/Component/Locale/Locale.php @@ -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[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(); } /** diff --git a/src/Symfony/Component/Locale/Resources/data/UPDATE.txt b/src/Symfony/Component/Locale/Resources/data/UPDATE.txt index aee00ef6cb..8d1d6c22ee 100644 --- a/src/Symfony/Component/Locale/Resources/data/UPDATE.txt +++ b/src/Symfony/Component/Locale/Resources/data/UPDATE.txt @@ -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. diff --git a/src/Symfony/Component/Locale/Resources/data/build-data.php b/src/Symfony/Component/Locale/Resources/data/build-data.php index 28c2ba2e6b..1fe0ca8766 100644 --- a/src/Symfony/Component/Locale/Resources/data/build-data.php +++ b/src/Symfony/Component/Locale/Resources/data/build-data.php @@ -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 = <<