From 0d0a8d4649625124a3d99f44ec5449af3e279216 Mon Sep 17 00:00:00 2001 From: Eriksen Costa Date: Tue, 10 Jul 2012 02:06:21 -0300 Subject: [PATCH 01/15] [Locale] updated script to generate separated data directories for different ICU releases --- .../Locale/Resources/data/UPDATE.txt | 21 +- .../Component/Locale/Resources/data/icu.ini | 12 + .../Locale/Resources/data/update-data.php | 219 +++++++++++++++--- 3 files changed, 217 insertions(+), 35 deletions(-) create mode 100644 src/Symfony/Component/Locale/Resources/data/icu.ini diff --git a/src/Symfony/Component/Locale/Resources/data/UPDATE.txt b/src/Symfony/Component/Locale/Resources/data/UPDATE.txt index b932ab62bb..822eea7628 100644 --- a/src/Symfony/Component/Locale/Resources/data/UPDATE.txt +++ b/src/Symfony/Component/Locale/Resources/data/UPDATE.txt @@ -1,13 +1,26 @@ How to update the ICU data ========================== -1. Checkout the current version of the ICU data files +The build script is a handy tool to generate or update the ICU data that ships +with Symfony2. You can pass the desired ICU version to build and the path to +the ICU binaries. Both arguments are optional, if not provided, the script will +try to build the latest available ICU data using the binaries available in the +environment path: - $ svn co http://source.icu-project.org/repos/icu/icu/trunk/source/data icu-data + $ php update-data.php 49 + $ php update-data.php 49 /path/to/icu/bin -2. Execute the build script +It is recommended to use the ICU binaries in the same version of the desired +version to build the data files. - $ php update-data.php /path/to/icu-data +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. + +The script requires `svn` (used to download the ICU data) and the `genrb` and +`icu-config` ICU binaries. .dat-package ------------ diff --git a/src/Symfony/Component/Locale/Resources/data/icu.ini b/src/Symfony/Component/Locale/Resources/data/icu.ini new file mode 100644 index 0000000000..7a1e63ede0 --- /dev/null +++ b/src/Symfony/Component/Locale/Resources/data/icu.ini @@ -0,0 +1,12 @@ +; 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 +4.2 = http://source.icu-project.org/repos/icu/icu/tags/release-4-2-1/source/data +4.4 = http://source.icu-project.org/repos/icu/icu/tags/release-4-4-2/source/data +4.6 = http://source.icu-project.org/repos/icu/icu/tags/release-4-6-1/source/data +4.8 = http://source.icu-project.org/repos/icu/icu/tags/release-4-8-1-1/source/data +49 = http://source.icu-project.org/repos/icu/icu/tags/release-49-1-2/source/data diff --git a/src/Symfony/Component/Locale/Resources/data/update-data.php b/src/Symfony/Component/Locale/Resources/data/update-data.php index f65eb99529..ee15b20137 100644 --- a/src/Symfony/Component/Locale/Resources/data/update-data.php +++ b/src/Symfony/Component/Locale/Resources/data/update-data.php @@ -74,18 +74,18 @@ function list_files($directory, $extension) return $files; } -function genrb($source, $target) +function genrb($source, $target, $icuBinPath = '', $params = '') { - exec('genrb -d '.$target.' '.$source.DIRECTORY_SEPARATOR.'*.txt', $output, $result); + exec($icuBinPath.'genrb --quiet '.$params.' -d '.$target.' '.$source.DIRECTORY_SEPARATOR.'*.txt', $output, $result); if ($result !== 0) { bailout('genrb failed'); } } -function genrb_file($target, $source, $locale) +function genrb_file($target, $source, $locale, $icuBinPath = '') { - exec('genrb -v -d '.$target.' '.$source.DIRECTORY_SEPARATOR.$locale.'.txt', $output, $result); + exec($icuBinPath.'genrb --quiet -d '.$target.' '.$source.DIRECTORY_SEPARATOR.$locale.'.txt', $output, $result); if ($result !== 0) { bailout('genrb failed'); @@ -106,7 +106,7 @@ function load_resource_bundle($locale, $directory) function get_data($index, $dataDir, $locale = 'en', $constraint = null) { $data = array(); - $bundle = load_resource_bundle($locale, __DIR__.DIRECTORY_SEPARATOR.$dataDir); + $bundle = load_resource_bundle($locale, $dataDir); foreach ($bundle->get($index) as $code => $name) { if (null !== $constraint) { @@ -125,6 +125,56 @@ function get_data($index, $dataDir, $locale = 'en', $constraint = null) return $data; } +function icu_version() { + exec('icu-config --version', $output, $result); + + if ($result !== 0 || !isset($output[0])) { + bailout('icu-config failed'); + } + + return $output[0]; +} + +function normalize_icu_version($version) { + preg_match('/^(?P[0-9]\.[0-9]|[0-9]{2,})/', $version, $matches); + + return $matches['version']; +} + +function download_icu_data($version) { + $icu = parse_ini_file(__DIR__.'/icu.ini'); + + if (!isset($icu[$version])) { + bailout('The version '.$version.' is not available in the datasource.ini file.'); + } + + $checkoutPath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'data-'.$version; + + exec('svn checkout '.$icu[$version].' '.$checkoutPath, $output, $result); + + if ($result !== 0) { + bailout('svn failed'); + } + + return $checkoutPath; +} + +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 = <<