Skip to content
Browse files

[Locale] don't create a "current" directory anymore, uses only the IC…

…U version as the name of the data directory
  • Loading branch information...
1 parent 3f2b4bf commit d9093609425d5ab11b5bfa08fb7fd3fa95c7f58a @themightyi themightyi committed Aug 5, 2012
View
3 .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
+ - php src/Symfony/Component/Locale/Resources/data/build-data.php
+ - export USE_INTL_ICU_DATA_VERSION=1
View
48 src/Symfony/Component/Locale/Locale.php
@@ -14,6 +14,11 @@
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 @@ public static function getCountries()
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 @@ public static function getLanguages()
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 @@ public static function getLocales()
}
/**
- * 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 @@ public static function getIcuVersion()
}
/**
- * 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 @@ public static function getIcuDataVersion()
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('USE_INTL_ICU_DATA_VERSION') && self::getIntlIcuVersion()) {
+ $dataVersion = self::getIntlIcuVersion();
+
+ preg_match('/^(?P<version>[0-9]\.[0-9]|[0-9]{2,})/', $dataVersion, $matches);
- 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';
+ $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
6 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.
View
31 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 = <<<TEMPLATE
@@ -291,7 +280,7 @@ function create_svn_info_file($source, $target)
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 @@ function create_svn_info_file($source, $target)
// 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
4 src/Symfony/Component/Locale/Resources/data/icu.ini
@@ -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
2 src/Symfony/Component/Locale/Stub/StubLocale.php
@@ -498,7 +498,7 @@ public static function getDataDirectory()
*/
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));

0 comments on commit d909360

Please sign in to comment.
Something went wrong with that request. Please try again.