Skip to content

Commit b096b61

Browse files
ro0NLfabpot
authored andcommitted
[Intl][4.3] Fix root fallback locale
1 parent 2e6ecd2 commit b096b61

File tree

20 files changed

+28
-2440
lines changed

20 files changed

+28
-2440
lines changed

Data/Generator/TimezoneDataGenerator.php

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
namespace Symfony\Component\Intl\Data\Generator;
1313

14+
use Symfony\Component\Filesystem\Filesystem;
1415
use Symfony\Component\Intl\Data\Bundle\Compiler\BundleCompilerInterface;
1516
use Symfony\Component\Intl\Data\Bundle\Reader\BundleEntryReaderInterface;
16-
use Symfony\Component\Intl\Data\Provider\RegionDataProvider;
1717
use Symfony\Component\Intl\Data\Util\ArrayAccessibleResourceBundle;
1818
use Symfony\Component\Intl\Data\Util\LocaleScanner;
1919
use Symfony\Component\Intl\Exception\MissingResourceException;
@@ -34,14 +34,6 @@ class TimezoneDataGenerator extends AbstractDataGenerator
3434
* @var string[]
3535
*/
3636
private $zoneIds = [];
37-
private $regionDataProvider;
38-
39-
public function __construct(BundleCompilerInterface $compiler, string $dirName, RegionDataProvider $regionDataProvider)
40-
{
41-
parent::__construct($compiler, $dirName);
42-
43-
$this->regionDataProvider = $regionDataProvider;
44-
}
4537

4638
/**
4739
* {@inheritdoc}
@@ -56,6 +48,9 @@ protected function scanLocales(LocaleScanner $scanner, $sourceDir)
5648
*/
5749
protected function compileTemporaryBundles(BundleCompilerInterface $compiler, $sourceDir, $tempDir)
5850
{
51+
$filesystem = new Filesystem();
52+
$filesystem->mkdir($tempDir.'/region');
53+
$compiler->compile($sourceDir.'/region', $tempDir.'/region');
5954
$compiler->compile($sourceDir.'/zone', $tempDir);
6055
$compiler->compile($sourceDir.'/misc/timezoneTypes.txt', $tempDir);
6156
$compiler->compile($sourceDir.'/misc/metaZones.txt', $tempDir);
@@ -83,17 +78,13 @@ protected function generateDataForLocale(BundleEntryReaderInterface $reader, $te
8378
while (null !== ($fallback = Locale::getFallback($fallback))) {
8479
$localeBundles[] = $reader->read($tempDir, $fallback);
8580
}
86-
if ('root' !== $displayLocale) {
87-
$localeBundles[] = $reader->read($tempDir, 'root');
88-
}
8981
$metadata = [];
9082
$data = [
9183
'Version' => $localeBundle['Version'],
9284
'Names' => $this->generateZones(
85+
$reader,
86+
$tempDir,
9387
$displayLocale,
94-
$reader->read($tempDir, 'timezoneTypes'),
95-
$reader->read($tempDir, 'metaZones'),
96-
$reader->read($tempDir, 'windowsZones'),
9788
$localeBundles,
9889
$metadata
9990
),
@@ -143,8 +134,11 @@ protected function generateDataForMeta(BundleEntryReaderInterface $reader, $temp
143134
/**
144135
* @param ArrayAccessibleResourceBundle[] $localeBundles
145136
*/
146-
private function generateZones(string $locale, ArrayAccessibleResourceBundle $typeBundle, ArrayAccessibleResourceBundle $metaBundle, ArrayAccessibleResourceBundle $windowsZonesBundle, array $localeBundles, array &$metadata = []): array
137+
private function generateZones(BundleEntryReaderInterface $reader, string $tempDir, string $locale, array $localeBundles, array &$metadata = []): array
147138
{
139+
$typeBundle = $reader->read($tempDir, 'timezoneTypes');
140+
$metaBundle = $reader->read($tempDir, 'metaZones');
141+
$windowsZonesBundle = $reader->read($tempDir, 'windowsZones');
148142
$accessor = static function (ArrayAccessibleResourceBundle $resourceBundle, array $indices) {
149143
$result = $resourceBundle;
150144
foreach ($indices as $indice) {
@@ -167,15 +161,15 @@ private function generateZones(string $locale, ArrayAccessibleResourceBundle $ty
167161

168162
return null;
169163
};
170-
$regionFormat = $accessor(['zoneStrings', 'regionFormat']) ?? '{0}';
171-
$fallbackFormat = $accessor(['zoneStrings', 'fallbackFormat']) ?? '{1} ({0})';
164+
$regionFormat = $reader->readEntry($tempDir, $locale, ['zoneStrings', 'regionFormat']);
165+
$fallbackFormat = $reader->readEntry($tempDir, $locale, ['zoneStrings', 'fallbackFormat']);
172166
$zoneToCountry = self::generateZoneToCountryMapping($windowsZonesBundle);
173-
$resolveName = function (string $id, string $city = null) use ($locale, $regionFormat, $fallbackFormat, $zoneToCountry): string {
167+
$resolveName = function (string $id, string $city = null) use ($reader, $tempDir, $locale, $regionFormat, $fallbackFormat, $zoneToCountry): ?string {
174168
if (isset($zoneToCountry[$id])) {
175169
try {
176-
$country = $this->regionDataProvider->getName($zoneToCountry[$id], $locale);
170+
$country = $reader->readEntry($tempDir.'/region', $locale, ['Countries', $zoneToCountry[$id]]);
177171
} catch (MissingResourceException $e) {
178-
$country = $this->regionDataProvider->getName($zoneToCountry[$id], 'en');
172+
return null;
179173
}
180174

181175
return null === $city ? str_replace('{0}', $country, $regionFormat) : str_replace(['{0}', '{1}'], [$city, $country], $fallbackFormat);
@@ -260,10 +254,9 @@ private static function generateZoneToCountryMapping(ArrayAccessibleResourceBund
260254

261255
foreach ($windowsZoneBundle['mapTimezones'] as $zoneInfo) {
262256
foreach ($zoneInfo as $region => $zones) {
263-
if (\in_array($region, ['001', 'ZZ'], true)) {
264-
continue;
257+
if (RegionDataGenerator::isValidCountryCode($region)) {
258+
$mapping += array_fill_keys(explode(' ', $zones), $region);
265259
}
266-
$mapping += array_fill_keys(explode(' ', $zones), $region);
267260
}
268261
}
269262

Resources/bin/update-data.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@
200200
$generator = new LocaleDataGenerator($compiler, Intl::LOCALE_DIR);
201201
$generator->generateData($config);
202202

203-
echo "Generating zone data...\n";
203+
echo "Generating timezone data...\n";
204204

205-
$generator = new TimezoneDataGenerator($compiler, Intl::TIMEZONE_DIR, new RegionDataProvider($jsonDir.'/'.Intl::REGION_DIR, $reader));
205+
$generator = new TimezoneDataGenerator($compiler, Intl::TIMEZONE_DIR);
206206
$generator->generateData($config);
207207

208208
echo "Resource bundle compilation complete.\n";

0 commit comments

Comments
 (0)