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