[Intl] Apply localeDisplayPattern and fix locale generation
This commit is contained in:
parent
7596da1cdc
commit
bf50b61f2a
@ -12,8 +12,9 @@
|
||||
namespace Symfony\Component\Intl\Data\Generator;
|
||||
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Intl\Data\Bundle\Compiler\GenrbCompiler;
|
||||
use Symfony\Component\Intl\Data\Bundle\Reader\BundleReaderInterface;
|
||||
use Symfony\Component\Intl\Data\Bundle\Compiler\BundleCompilerInterface;
|
||||
use Symfony\Component\Intl\Data\Bundle\Reader\BundleEntryReader;
|
||||
use Symfony\Component\Intl\Data\Bundle\Reader\BundleEntryReaderInterface;
|
||||
use Symfony\Component\Intl\Data\Bundle\Reader\IntlBundleReader;
|
||||
use Symfony\Component\Intl\Data\Util\LocaleScanner;
|
||||
|
||||
@ -29,7 +30,7 @@ abstract class AbstractDataGenerator
|
||||
private $compiler;
|
||||
private $dirName;
|
||||
|
||||
public function __construct(GenrbCompiler $compiler, string $dirName)
|
||||
public function __construct(BundleCompilerInterface $compiler, string $dirName)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$this->dirName = $dirName;
|
||||
@ -39,7 +40,7 @@ abstract class AbstractDataGenerator
|
||||
{
|
||||
$filesystem = new Filesystem();
|
||||
$localeScanner = new LocaleScanner();
|
||||
$reader = new IntlBundleReader();
|
||||
$reader = new BundleEntryReader(new IntlBundleReader());
|
||||
|
||||
$writers = $config->getBundleWriters();
|
||||
$tempDir = sys_get_temp_dir().'/icu-data-'.$this->dirName;
|
||||
@ -98,36 +99,32 @@ abstract class AbstractDataGenerator
|
||||
abstract protected function scanLocales(LocaleScanner $scanner, $sourceDir);
|
||||
|
||||
/**
|
||||
* @param GenrbCompiler $compiler
|
||||
* @param string $sourceDir
|
||||
* @param string $tempDir
|
||||
*/
|
||||
abstract protected function compileTemporaryBundles(GenrbCompiler $compiler, $sourceDir, $tempDir);
|
||||
abstract protected function compileTemporaryBundles(BundleCompilerInterface $compiler, $sourceDir, $tempDir);
|
||||
|
||||
abstract protected function preGenerate();
|
||||
|
||||
/**
|
||||
* @param BundleReaderInterface $reader
|
||||
* @param string $tempDir
|
||||
* @param string $displayLocale
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
abstract protected function generateDataForLocale(BundleReaderInterface $reader, $tempDir, $displayLocale);
|
||||
abstract protected function generateDataForLocale(BundleEntryReaderInterface $reader, $tempDir, $displayLocale);
|
||||
|
||||
/**
|
||||
* @param BundleReaderInterface $reader
|
||||
* @param string $tempDir
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
abstract protected function generateDataForRoot(BundleReaderInterface $reader, $tempDir);
|
||||
abstract protected function generateDataForRoot(BundleEntryReaderInterface $reader, $tempDir);
|
||||
|
||||
/**
|
||||
* @param BundleReaderInterface $reader
|
||||
* @param string $tempDir
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
abstract protected function generateDataForMeta(BundleReaderInterface $reader, $tempDir);
|
||||
abstract protected function generateDataForMeta(BundleEntryReaderInterface $reader, $tempDir);
|
||||
}
|
||||
|
@ -11,8 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\Intl\Data\Generator;
|
||||
|
||||
use Symfony\Component\Intl\Data\Bundle\Compiler\GenrbCompiler;
|
||||
use Symfony\Component\Intl\Data\Bundle\Reader\BundleReaderInterface;
|
||||
use Symfony\Component\Intl\Data\Bundle\Compiler\BundleCompilerInterface;
|
||||
use Symfony\Component\Intl\Data\Bundle\Reader\BundleEntryReaderInterface;
|
||||
use Symfony\Component\Intl\Data\Util\ArrayAccessibleResourceBundle;
|
||||
use Symfony\Component\Intl\Data\Util\LocaleScanner;
|
||||
|
||||
@ -59,7 +59,7 @@ class CurrencyDataGenerator extends AbstractDataGenerator
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function compileTemporaryBundles(GenrbCompiler $compiler, $sourceDir, $tempDir)
|
||||
protected function compileTemporaryBundles(BundleCompilerInterface $compiler, $sourceDir, $tempDir)
|
||||
{
|
||||
$compiler->compile($sourceDir.'/curr', $tempDir);
|
||||
$compiler->compile($sourceDir.'/misc/currencyNumericCodes.txt', $tempDir);
|
||||
@ -76,7 +76,7 @@ class CurrencyDataGenerator extends AbstractDataGenerator
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function generateDataForLocale(BundleReaderInterface $reader, $tempDir, $displayLocale)
|
||||
protected function generateDataForLocale(BundleEntryReaderInterface $reader, $tempDir, $displayLocale)
|
||||
{
|
||||
$localeBundle = $reader->read($tempDir, $displayLocale);
|
||||
|
||||
@ -95,7 +95,7 @@ class CurrencyDataGenerator extends AbstractDataGenerator
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function generateDataForRoot(BundleReaderInterface $reader, $tempDir)
|
||||
protected function generateDataForRoot(BundleEntryReaderInterface $reader, $tempDir)
|
||||
{
|
||||
$rootBundle = $reader->read($tempDir, 'root');
|
||||
|
||||
@ -108,7 +108,7 @@ class CurrencyDataGenerator extends AbstractDataGenerator
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function generateDataForMeta(BundleReaderInterface $reader, $tempDir)
|
||||
protected function generateDataForMeta(BundleEntryReaderInterface $reader, $tempDir)
|
||||
{
|
||||
$rootBundle = $reader->read($tempDir, 'root');
|
||||
$supplementalDataBundle = $reader->read($tempDir, 'supplementalData');
|
||||
|
@ -11,8 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\Intl\Data\Generator;
|
||||
|
||||
use Symfony\Component\Intl\Data\Bundle\Compiler\GenrbCompiler;
|
||||
use Symfony\Component\Intl\Data\Bundle\Reader\BundleReaderInterface;
|
||||
use Symfony\Component\Intl\Data\Bundle\Compiler\BundleCompilerInterface;
|
||||
use Symfony\Component\Intl\Data\Bundle\Reader\BundleEntryReaderInterface;
|
||||
use Symfony\Component\Intl\Data\Util\ArrayAccessibleResourceBundle;
|
||||
use Symfony\Component\Intl\Data\Util\LocaleScanner;
|
||||
use Symfony\Component\Intl\Exception\RuntimeException;
|
||||
@ -108,7 +108,7 @@ class LanguageDataGenerator extends AbstractDataGenerator
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function compileTemporaryBundles(GenrbCompiler $compiler, $sourceDir, $tempDir)
|
||||
protected function compileTemporaryBundles(BundleCompilerInterface $compiler, $sourceDir, $tempDir)
|
||||
{
|
||||
$compiler->compile($sourceDir.'/lang', $tempDir);
|
||||
$compiler->compile($sourceDir.'/misc/metadata.txt', $tempDir);
|
||||
@ -125,7 +125,7 @@ class LanguageDataGenerator extends AbstractDataGenerator
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function generateDataForLocale(BundleReaderInterface $reader, $tempDir, $displayLocale)
|
||||
protected function generateDataForLocale(BundleEntryReaderInterface $reader, $tempDir, $displayLocale)
|
||||
{
|
||||
$localeBundle = $reader->read($tempDir, $displayLocale);
|
||||
|
||||
@ -145,14 +145,14 @@ class LanguageDataGenerator extends AbstractDataGenerator
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function generateDataForRoot(BundleReaderInterface $reader, $tempDir)
|
||||
protected function generateDataForRoot(BundleEntryReaderInterface $reader, $tempDir)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function generateDataForMeta(BundleReaderInterface $reader, $tempDir)
|
||||
protected function generateDataForMeta(BundleEntryReaderInterface $reader, $tempDir)
|
||||
{
|
||||
$rootBundle = $reader->read($tempDir, 'root');
|
||||
$metadataBundle = $reader->read($tempDir, 'metadata');
|
||||
|
@ -12,128 +12,126 @@
|
||||
namespace Symfony\Component\Intl\Data\Generator;
|
||||
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Intl\Data\Bundle\Compiler\BundleCompilerInterface;
|
||||
use Symfony\Component\Intl\Data\Bundle\Reader\BundleEntryReaderInterface;
|
||||
use Symfony\Component\Intl\Data\Provider\LanguageDataProvider;
|
||||
use Symfony\Component\Intl\Data\Provider\RegionDataProvider;
|
||||
use Symfony\Component\Intl\Data\Provider\ScriptDataProvider;
|
||||
use Symfony\Component\Intl\Data\Util\LocaleScanner;
|
||||
use Symfony\Component\Intl\Exception\MissingResourceException;
|
||||
use Symfony\Component\Intl\Exception\ResourceBundleNotFoundException;
|
||||
use Symfony\Component\Intl\Locale;
|
||||
|
||||
/**
|
||||
* The rule for compiling the locale bundle.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
* @author Roland Franssen <franssen.roland@gmail.com>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class LocaleDataGenerator
|
||||
class LocaleDataGenerator extends AbstractDataGenerator
|
||||
{
|
||||
private $dirName;
|
||||
private $languageDataProvider;
|
||||
private $scriptDataProvider;
|
||||
private $regionDataProvider;
|
||||
private $locales;
|
||||
private $localeAliases;
|
||||
private $fallbackMapping;
|
||||
private $fallbackCache = [];
|
||||
|
||||
public function __construct(string $dirName, LanguageDataProvider $languageDataProvider, ScriptDataProvider $scriptDataProvider, RegionDataProvider $regionDataProvider)
|
||||
public function __construct(BundleCompilerInterface $compiler, string $dirName, LanguageDataProvider $languageDataProvider, ScriptDataProvider $scriptDataProvider, RegionDataProvider $regionDataProvider)
|
||||
{
|
||||
$this->dirName = $dirName;
|
||||
parent::__construct($compiler, $dirName);
|
||||
|
||||
$this->languageDataProvider = $languageDataProvider;
|
||||
$this->scriptDataProvider = $scriptDataProvider;
|
||||
$this->regionDataProvider = $regionDataProvider;
|
||||
}
|
||||
|
||||
public function generateData(GeneratorConfig $config)
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function scanLocales(LocaleScanner $scanner, $sourceDir)
|
||||
{
|
||||
$filesystem = new Filesystem();
|
||||
$localeScanner = new LocaleScanner();
|
||||
$this->locales = $scanner->scanLocales($sourceDir.'/locales');
|
||||
$this->localeAliases = $scanner->scanAliases($sourceDir.'/locales');
|
||||
$this->fallbackMapping = $this->generateFallbackMapping(array_diff($this->locales, array_keys($this->localeAliases)), $this->localeAliases);
|
||||
|
||||
$writers = $config->getBundleWriters();
|
||||
|
||||
// Prepare filesystem directories
|
||||
foreach ($writers as $targetDir => $writer) {
|
||||
$filesystem->remove($targetDir.'/'.$this->dirName);
|
||||
$filesystem->mkdir($targetDir.'/'.$this->dirName);
|
||||
return $this->locales;
|
||||
}
|
||||
|
||||
$locales = $localeScanner->scanLocales($config->getSourceDir().'/locales');
|
||||
$aliases = $localeScanner->scanAliases($config->getSourceDir().'/locales');
|
||||
$parents = $localeScanner->scanParents($config->getSourceDir().'/locales');
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function compileTemporaryBundles(BundleCompilerInterface $compiler, $sourceDir, $tempDir)
|
||||
{
|
||||
$filesystem = new Filesystem();
|
||||
$filesystem->mkdir($tempDir.'/lang');
|
||||
$compiler->compile($sourceDir.'/lang', $tempDir.'/lang');
|
||||
}
|
||||
|
||||
// Flip to facilitate lookup
|
||||
$flippedLocales = array_flip($locales);
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function preGenerate()
|
||||
{
|
||||
$this->fallbackCache = [];
|
||||
}
|
||||
|
||||
// Don't generate names for aliases (names will be generated for the
|
||||
// locale they are duplicating)
|
||||
$displayLocales = array_diff_key($flippedLocales, $aliases);
|
||||
|
||||
ksort($displayLocales);
|
||||
|
||||
// Generate a list of (existing) locale fallbacks
|
||||
$fallbackMapping = $this->generateFallbackMapping($displayLocales, $aliases);
|
||||
|
||||
$localeNames = [];
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function generateDataForLocale(BundleEntryReaderInterface $reader, $tempDir, $displayLocale)
|
||||
{
|
||||
// Generate aliases, needed to enable proper fallback from alias to its
|
||||
// target
|
||||
if (isset($this->localeAliases[$displayLocale])) {
|
||||
return ['%%ALIAS' => $this->localeAliases[$displayLocale]];
|
||||
}
|
||||
|
||||
// Generate locale names for all locales that have translations in
|
||||
// at least the language or the region bundle
|
||||
foreach ($displayLocales as $displayLocale => $_) {
|
||||
$localeNames[$displayLocale] = [];
|
||||
try {
|
||||
$displayFormat = $reader->readEntry($tempDir.'/lang', $displayLocale, ['localeDisplayPattern']);
|
||||
} catch (MissingResourceException $e) {
|
||||
$displayFormat = $reader->readEntry($tempDir.'/lang', 'root', ['localeDisplayPattern']);
|
||||
}
|
||||
$pattern = $displayFormat['pattern'] ?? '{0} ({1})';
|
||||
$separator = $displayFormat['separator'] ?? '{0}, {1}';
|
||||
$localeNames = [];
|
||||
foreach ($this->locales as $locale) {
|
||||
// Ensure a normalized list of pure locales
|
||||
if (isset($this->localeAliases[$displayLocale]) || \Locale::getAllVariants($locale)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($locales as $locale) {
|
||||
try {
|
||||
// Generate a locale name in the language of each display locale
|
||||
// Each locale name has the form: "Language (Script, Region, Variant1, ...)
|
||||
// Script, Region and Variants are optional. If none of them is
|
||||
// available, the braces are not printed.
|
||||
if (null !== ($name = $this->generateLocaleName($locale, $displayLocale))) {
|
||||
$localeNames[$displayLocale][$locale] = $name;
|
||||
}
|
||||
$localeNames[$locale] = $this->generateLocaleName($locale, $displayLocale, $pattern, $separator);
|
||||
} catch (MissingResourceException $e) {
|
||||
} catch (ResourceBundleNotFoundException $e) {
|
||||
}
|
||||
// Silently ignore incomplete locale names
|
||||
// In this case one should configure at least one fallback locale that is complete (e.g. English) during
|
||||
// runtime. Alternatively a translation for the missing resource can be proposed upstream.
|
||||
}
|
||||
}
|
||||
|
||||
// Process again to de-duplicate locales and their fallback locales
|
||||
// Only keep the differences
|
||||
foreach ($displayLocales as $displayLocale => $_) {
|
||||
$fallback = $displayLocale;
|
||||
|
||||
while (isset($fallbackMapping[$fallback])) {
|
||||
$fallback = $fallbackMapping[$fallback];
|
||||
$localeNames[$displayLocale] = array_diff(
|
||||
$localeNames[$displayLocale],
|
||||
$localeNames[$fallback]
|
||||
);
|
||||
while (isset($this->fallbackMapping[$fallback])) {
|
||||
if (!isset($this->fallbackCache[$fallback = $this->fallbackMapping[$fallback]])) {
|
||||
$this->fallbackCache[$fallback] = $this->generateDataForLocale($reader, $tempDir, $fallback) ?: [];
|
||||
}
|
||||
|
||||
// If no names remain to be saved for the current locale, skip it
|
||||
if (0 === \count($localeNames[$displayLocale])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($writers as $targetDir => $writer) {
|
||||
$writer->write($targetDir.'/'.$this->dirName, $displayLocale, [
|
||||
'Names' => $localeNames[$displayLocale],
|
||||
]);
|
||||
if (isset($this->fallbackCache[$fallback]['Names'])) {
|
||||
$localeNames = array_diff($localeNames, $this->fallbackCache[$fallback]['Names']);
|
||||
}
|
||||
}
|
||||
|
||||
// Generate aliases, needed to enable proper fallback from alias to its
|
||||
// target
|
||||
foreach ($aliases as $alias => $aliasOf) {
|
||||
foreach ($writers as $targetDir => $writer) {
|
||||
$writer->write($targetDir.'/'.$this->dirName, $alias, [
|
||||
'%%ALIAS' => $aliasOf,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Create root file which maps locale codes to locale codes, for fallback
|
||||
foreach ($writers as $targetDir => $writer) {
|
||||
$writer->write($targetDir.'/'.$this->dirName, 'meta', [
|
||||
'Locales' => $locales,
|
||||
'Aliases' => $aliases,
|
||||
]);
|
||||
if ($localeNames) {
|
||||
return ['Names' => $localeNames];
|
||||
}
|
||||
|
||||
// Write parents locale file for the Translation component
|
||||
@ -143,72 +141,54 @@ class LocaleDataGenerator
|
||||
);
|
||||
}
|
||||
|
||||
private function generateLocaleName($locale, $displayLocale)
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function generateDataForRoot(BundleEntryReaderInterface $reader, $tempDir)
|
||||
{
|
||||
$name = null;
|
||||
|
||||
$lang = \Locale::getPrimaryLanguage($locale);
|
||||
$script = \Locale::getScript($locale);
|
||||
$region = \Locale::getRegion($locale);
|
||||
$variants = \Locale::getAllVariants($locale);
|
||||
|
||||
// Currently the only available variant is POSIX, which we don't want
|
||||
// to include in the list
|
||||
if (\count($variants) > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Some languages are translated together with their region,
|
||||
// i.e. "en_GB" is translated as "British English"
|
||||
// we don't include these languages though because they mess up
|
||||
// the name sorting
|
||||
// $name = $this->langBundle->getLanguageName($displayLocale, $lang, $region);
|
||||
|
||||
// Some languages are not translated
|
||||
// Example: "az" (Azerbaijani) has no translation in "af" (Afrikaans)
|
||||
if (null === ($name = $this->languageDataProvider->getName($lang, $displayLocale))) {
|
||||
return;
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function generateDataForMeta(BundleEntryReaderInterface $reader, $tempDir)
|
||||
{
|
||||
if ($this->locales || $this->localeAliases) {
|
||||
return [
|
||||
'Locales' => $this->locales,
|
||||
'Aliases' => $this->localeAliases,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// "as" (Assamese) has no "Variants" block
|
||||
//if (!$langBundle->get('Variants')) {
|
||||
// continue;
|
||||
//}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function generateLocaleName($locale, $displayLocale, $pattern, $separator)
|
||||
{
|
||||
// Apply generic notation using square brackets as described per http://cldr.unicode.org/translation/language-names
|
||||
$name = str_replace(['(', ')'], ['[', ']'], $this->languageDataProvider->getName(\Locale::getPrimaryLanguage($locale), $displayLocale));
|
||||
$extras = [];
|
||||
|
||||
// Discover the name of the script part of the locale
|
||||
// i.e. in zh_Hans_MO, "Hans" is the script
|
||||
if ($script) {
|
||||
// Some scripts are not translated into every language
|
||||
if (null === ($scriptName = $this->scriptDataProvider->getName($script, $displayLocale))) {
|
||||
return;
|
||||
}
|
||||
|
||||
$extras[] = $scriptName;
|
||||
if ($script = \Locale::getScript($locale)) {
|
||||
$extras[] = str_replace(['(', ')'], ['[', ']'], $this->scriptDataProvider->getName($script, $displayLocale));
|
||||
}
|
||||
|
||||
// Discover the name of the region part of the locale
|
||||
// i.e. in de_AT, "AT" is the region
|
||||
if ($region) {
|
||||
// Some regions are not translated into every language
|
||||
if (null === ($regionName = $this->regionDataProvider->getName($region, $displayLocale))) {
|
||||
return;
|
||||
if ($region = \Locale::getRegion($locale)) {
|
||||
$extras[] = str_replace(['(', ')'], ['[', ']'], $this->regionDataProvider->getName($region, $displayLocale));
|
||||
}
|
||||
|
||||
$extras[] = $regionName;
|
||||
if ($extras) {
|
||||
$extra = array_shift($extras);
|
||||
foreach ($extras as $part) {
|
||||
$extra = str_replace(['{0}', '{1}'], [$extra, $part], $separator);
|
||||
}
|
||||
|
||||
if (\count($extras) > 0) {
|
||||
// Remove any existing extras
|
||||
// For example, in German, zh_Hans is "Chinesisch (vereinfacht)".
|
||||
// The latter is the script part which is already included in the
|
||||
// extras and will be appended again with the other extras.
|
||||
if (preg_match('/^(.+)\s+\([^\)]+\)$/', $name, $matches)) {
|
||||
$name = $matches[1];
|
||||
}
|
||||
|
||||
$name .= ' ('.implode(', ', $extras).')';
|
||||
$name = str_replace(['{0}', '{1}'], [$name, $extra], $pattern);
|
||||
}
|
||||
|
||||
return $name;
|
||||
@ -216,6 +196,7 @@ class LocaleDataGenerator
|
||||
|
||||
private function generateFallbackMapping(array $displayLocales, array $aliases)
|
||||
{
|
||||
$displayLocales = array_flip($displayLocales);
|
||||
$mapping = [];
|
||||
|
||||
foreach ($displayLocales as $displayLocale => $_) {
|
||||
|
@ -11,8 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\Intl\Data\Generator;
|
||||
|
||||
use Symfony\Component\Intl\Data\Bundle\Compiler\GenrbCompiler;
|
||||
use Symfony\Component\Intl\Data\Bundle\Reader\BundleReaderInterface;
|
||||
use Symfony\Component\Intl\Data\Bundle\Compiler\BundleCompilerInterface;
|
||||
use Symfony\Component\Intl\Data\Bundle\Reader\BundleEntryReaderInterface;
|
||||
use Symfony\Component\Intl\Data\Util\ArrayAccessibleResourceBundle;
|
||||
use Symfony\Component\Intl\Data\Util\LocaleScanner;
|
||||
|
||||
@ -65,7 +65,7 @@ class RegionDataGenerator extends AbstractDataGenerator
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function compileTemporaryBundles(GenrbCompiler $compiler, $sourceDir, $tempDir)
|
||||
protected function compileTemporaryBundles(BundleCompilerInterface $compiler, $sourceDir, $tempDir)
|
||||
{
|
||||
$compiler->compile($sourceDir.'/region', $tempDir);
|
||||
}
|
||||
@ -81,7 +81,7 @@ class RegionDataGenerator extends AbstractDataGenerator
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function generateDataForLocale(BundleReaderInterface $reader, $tempDir, $displayLocale)
|
||||
protected function generateDataForLocale(BundleEntryReaderInterface $reader, $tempDir, $displayLocale)
|
||||
{
|
||||
$localeBundle = $reader->read($tempDir, $displayLocale);
|
||||
|
||||
@ -101,14 +101,14 @@ class RegionDataGenerator extends AbstractDataGenerator
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function generateDataForRoot(BundleReaderInterface $reader, $tempDir)
|
||||
protected function generateDataForRoot(BundleEntryReaderInterface $reader, $tempDir)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function generateDataForMeta(BundleReaderInterface $reader, $tempDir)
|
||||
protected function generateDataForMeta(BundleEntryReaderInterface $reader, $tempDir)
|
||||
{
|
||||
$rootBundle = $reader->read($tempDir, 'root');
|
||||
|
||||
|
@ -11,8 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\Intl\Data\Generator;
|
||||
|
||||
use Symfony\Component\Intl\Data\Bundle\Compiler\GenrbCompiler;
|
||||
use Symfony\Component\Intl\Data\Bundle\Reader\BundleReaderInterface;
|
||||
use Symfony\Component\Intl\Data\Bundle\Compiler\BundleCompilerInterface;
|
||||
use Symfony\Component\Intl\Data\Bundle\Reader\BundleEntryReaderInterface;
|
||||
use Symfony\Component\Intl\Data\Util\LocaleScanner;
|
||||
|
||||
/**
|
||||
@ -46,7 +46,7 @@ class ScriptDataGenerator extends AbstractDataGenerator
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function compileTemporaryBundles(GenrbCompiler $compiler, $sourceDir, $tempDir)
|
||||
protected function compileTemporaryBundles(BundleCompilerInterface $compiler, $sourceDir, $tempDir)
|
||||
{
|
||||
$compiler->compile($sourceDir.'/lang', $tempDir);
|
||||
}
|
||||
@ -62,7 +62,7 @@ class ScriptDataGenerator extends AbstractDataGenerator
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function generateDataForLocale(BundleReaderInterface $reader, $tempDir, $displayLocale)
|
||||
protected function generateDataForLocale(BundleEntryReaderInterface $reader, $tempDir, $displayLocale)
|
||||
{
|
||||
$localeBundle = $reader->read($tempDir, $displayLocale);
|
||||
|
||||
@ -82,14 +82,14 @@ class ScriptDataGenerator extends AbstractDataGenerator
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function generateDataForRoot(BundleReaderInterface $reader, $tempDir)
|
||||
protected function generateDataForRoot(BundleEntryReaderInterface $reader, $tempDir)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function generateDataForMeta(BundleReaderInterface $reader, $tempDir)
|
||||
protected function generateDataForMeta(BundleEntryReaderInterface $reader, $tempDir)
|
||||
{
|
||||
$rootBundle = $reader->read($tempDir, 'root');
|
||||
|
||||
|
@ -171,18 +171,10 @@ echo "Preparing resource bundle compilation (version $icuVersionInDownload)...\n
|
||||
|
||||
$compiler = new GenrbCompiler($genrb, $genrbEnv);
|
||||
$config = new GeneratorConfig($sourceDir.'/data', $icuVersionInDownload);
|
||||
$jsonDir = dirname(__DIR__).'/data';
|
||||
$targetDirs = [$jsonDir];
|
||||
$workingDirs = [$jsonDir];
|
||||
|
||||
$baseDir = dirname(__DIR__).'/data';
|
||||
|
||||
//$txtDir = $baseDir.'/txt';
|
||||
$jsonDir = $baseDir;
|
||||
//$phpDir = $baseDir.'/'.Intl::PHP;
|
||||
//$resDir = $baseDir.'/'.Intl::RB_V2;
|
||||
|
||||
$targetDirs = [$jsonDir/*, $resDir*/];
|
||||
$workingDirs = [$jsonDir/*, $txtDir, $resDir*/];
|
||||
|
||||
//$config->addBundleWriter($txtDir, new TextBundleWriter());
|
||||
$config->addBundleWriter($jsonDir, new JsonBundleWriter());
|
||||
|
||||
echo "Starting resource bundle compilation. This may take a while...\n";
|
||||
@ -208,56 +200,33 @@ echo "Generating language data...\n";
|
||||
$generator = new LanguageDataGenerator($compiler, Intl::LANGUAGE_DIR);
|
||||
$generator->generateData($config);
|
||||
|
||||
//echo "Compiling...\n";
|
||||
//
|
||||
//$compiler->compile($txtDir.'/'.Intl::LANGUAGE_DIR, $resDir.'/'.Intl::LANGUAGE_DIR);
|
||||
|
||||
echo "Generating script data...\n";
|
||||
|
||||
$generator = new ScriptDataGenerator($compiler, Intl::SCRIPT_DIR);
|
||||
$generator->generateData($config);
|
||||
|
||||
//echo "Compiling...\n";
|
||||
//
|
||||
//$compiler->compile($txtDir.'/'.Intl::SCRIPT_DIR, $resDir.'/'.Intl::SCRIPT_DIR);
|
||||
|
||||
echo "Generating region data...\n";
|
||||
|
||||
$generator = new RegionDataGenerator($compiler, Intl::REGION_DIR);
|
||||
$generator->generateData($config);
|
||||
|
||||
//echo "Compiling...\n";
|
||||
//
|
||||
//$compiler->compile($txtDir.'/'.Intl::REGION_DIR, $resDir.'/'.Intl::REGION_DIR);
|
||||
|
||||
echo "Generating currency data...\n";
|
||||
|
||||
$generator = new CurrencyDataGenerator($compiler, Intl::CURRENCY_DIR);
|
||||
$generator->generateData($config);
|
||||
|
||||
//echo "Compiling...\n";
|
||||
//
|
||||
//$compiler->compile($txtDir.'/'.Intl::CURRENCY_DIR, $resDir.'/'.Intl::CURRENCY_DIR);
|
||||
|
||||
echo "Generating locale data...\n";
|
||||
|
||||
$reader = new BundleEntryReader(new JsonBundleReader());
|
||||
|
||||
$generator = new LocaleDataGenerator(
|
||||
$compiler,
|
||||
Intl::LOCALE_DIR,
|
||||
new LanguageDataProvider($jsonDir.'/'.Intl::LANGUAGE_DIR, $reader),
|
||||
new ScriptDataProvider($jsonDir.'/'.Intl::SCRIPT_DIR, $reader),
|
||||
new RegionDataProvider($jsonDir.'/'.Intl::REGION_DIR, $reader)
|
||||
);
|
||||
|
||||
$generator->generateData($config);
|
||||
|
||||
//echo "Compiling...\n";
|
||||
//
|
||||
//$compiler->compile($txtDir.'/'.Intl::LOCALE_DIR, $resDir.'/'.Intl::LOCALE_DIR);
|
||||
//
|
||||
//$filesystem->remove($txtDir);
|
||||
|
||||
echo "Generating zone data...\n";
|
||||
|
||||
$generator = new TimezoneDataGenerator($compiler, Intl::TIMEZONE_DIR, new RegionDataProvider($jsonDir.'/'.Intl::REGION_DIR, $reader));
|
||||
|
Reference in New Issue
Block a user