[Locale] updated ICU data paths

This commit is contained in:
Eriksen Costa 2012-07-29 23:49:13 -03:00
parent 64ccee7f98
commit 5fd4eb1c3a
2 changed files with 29 additions and 4 deletions

View File

@ -43,7 +43,7 @@ class Locale extends \Locale
public static function getDisplayCountries($locale)
{
if (!isset(self::$countries[$locale])) {
$bundle = \ResourceBundle::create($locale, __DIR__.'/Resources/data/region');
$bundle = \ResourceBundle::create($locale, self::getDataDirectory().'/region');
if (null === $bundle) {
throw new \RuntimeException(sprintf('The country resource bundle could not be loaded for locale "%s"', $locale));
@ -98,7 +98,7 @@ class Locale extends \Locale
public static function getDisplayLanguages($locale)
{
if (!isset(self::$languages[$locale])) {
$bundle = \ResourceBundle::create($locale, __DIR__.'/Resources/data/lang');
$bundle = \ResourceBundle::create($locale, self::getDataDirectory().'/lang');
if (null === $bundle) {
throw new \RuntimeException(sprintf('The language resource bundle could not be loaded for locale "%s"', $locale));
@ -149,7 +149,7 @@ class Locale extends \Locale
public static function getDisplayLocales($locale)
{
if (!isset(self::$locales[$locale])) {
$bundle = \ResourceBundle::create($locale, __DIR__.'/Resources/data/names');
$bundle = \ResourceBundle::create($locale, self::getDataDirectory().'/names');
if (null === $bundle) {
throw new \RuntimeException(sprintf('The locale resource bundle could not be loaded for locale "%s"', $locale));
@ -237,6 +237,28 @@ class Locale extends \Locale
return trim($matches[1]);
}
public static function getDataVersion()
{
static $dataVersion;
if (null === $dataVersion) {
$dataVersion = 'current';
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';
}
}
return $dataVersion;
}
public static function getDataDirectory()
{
return __DIR__.'/Resources/data/'.self::getDataVersion();
}
/**
* Returns the fallback locale for a given locale, if any
*

View File

@ -11,6 +11,7 @@
namespace Symfony\Component\Locale\Stub;
use Symfony\Component\Locale\Locale;
use Symfony\Component\Locale\Exception\NotImplementedException;
use Symfony\Component\Locale\Exception\MethodNotImplementedException;
@ -480,12 +481,14 @@ class StubLocale
*/
private static function getStubData($locale, $cacheVariable, $stubDataDir)
{
$dataDirectory = Locale::getDataDirectory();
if ('en' !== $locale) {
throw new \InvalidArgumentException(sprintf('Only the \'en\' locale is supported. %s', NotImplementedException::INTL_INSTALL_MESSAGE));
}
if (empty(self::${$cacheVariable})) {
self::${$cacheVariable} = include __DIR__.'/../Resources/data/stub/'.$stubDataDir.'/en.php';
self::${$cacheVariable} = include __DIR__.'/../Resources/data/'.$dataDirectory.'/stub/'.$stubDataDir.'/en.php';
}
return self::${$cacheVariable};