diff --git a/src/Symfony/Component/Locale/Locale.php b/src/Symfony/Component/Locale/Locale.php index 74f04ec161..c1d00e8243 100644 --- a/src/Symfony/Component/Locale/Locale.php +++ b/src/Symfony/Component/Locale/Locale.php @@ -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 * diff --git a/src/Symfony/Component/Locale/Stub/StubLocale.php b/src/Symfony/Component/Locale/Stub/StubLocale.php index bf8d293dee..eec8918ff8 100644 --- a/src/Symfony/Component/Locale/Stub/StubLocale.php +++ b/src/Symfony/Component/Locale/Stub/StubLocale.php @@ -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};