Skip to content

Commit 1449c4e

Browse files
Sync intl scripts
1 parent 7b9d95f commit 1449c4e

File tree

220 files changed

+536
-59
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+536
-59
lines changed

Data/Bundle/Compiler/BundleCompilerInterface.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ interface BundleCompilerInterface
2323
/**
2424
* Compiles a resource bundle at the given source to the given target
2525
* directory.
26-
*
27-
* @return void
2826
*/
29-
public function compile(string $sourcePath, string $targetDir);
27+
public function compile(string $sourcePath, string $targetDir): void;
3028
}

Data/Bundle/Reader/BufferedBundleReader.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
*/
2121
class BufferedBundleReader implements BundleReaderInterface
2222
{
23-
private BundleReaderInterface $reader;
2423
/** @var RingBuffer<string, mixed> */
2524
private RingBuffer $buffer;
2625

27-
public function __construct(BundleReaderInterface $reader, int $bufferSize)
28-
{
29-
$this->reader = $reader;
26+
public function __construct(
27+
private BundleReaderInterface $reader,
28+
int $bufferSize,
29+
) {
3030
$this->buffer = new RingBuffer($bufferSize);
3131
}
3232

Data/Bundle/Reader/BundleEntryReader.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
*/
2929
class BundleEntryReader implements BundleEntryReaderInterface
3030
{
31-
private BundleReaderInterface $reader;
32-
3331
/**
3432
* A mapping of locale aliases to locales.
3533
*/
@@ -38,9 +36,9 @@ class BundleEntryReader implements BundleEntryReaderInterface
3836
/**
3937
* Creates an entry reader based on the given resource bundle reader.
4038
*/
41-
public function __construct(BundleReaderInterface $reader)
42-
{
43-
$this->reader = $reader;
39+
public function __construct(
40+
private BundleReaderInterface $reader,
41+
) {
4442
}
4543

4644
/**

Data/Bundle/Writer/BundleWriterInterface.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,5 @@
2020
*/
2121
interface BundleWriterInterface
2222
{
23-
/**
24-
* @return void
25-
*/
26-
public function write(string $path, string $locale, mixed $data);
23+
public function write(string $path, string $locale, mixed $data): void;
2724
}

Data/Bundle/Writer/PhpBundleWriter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ class PhpBundleWriter implements BundleWriterInterface
2525
public function write(string $path, string $locale, mixed $data): void
2626
{
2727
$template = <<<'TEMPLATE'
28-
<?php
28+
<?php
2929
30-
return %s;
30+
return %s;
3131

32-
TEMPLATE;
32+
TEMPLATE;
3333

3434
if ($data instanceof \Traversable) {
3535
$data = iterator_to_array($data);

Data/Generator/AbstractDataGenerator.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@
2727
*/
2828
abstract class AbstractDataGenerator
2929
{
30-
private BundleCompilerInterface $compiler;
31-
private string $dirName;
32-
33-
public function __construct(BundleCompilerInterface $compiler, string $dirName)
34-
{
35-
$this->compiler = $compiler;
36-
$this->dirName = $dirName;
30+
public function __construct(
31+
private BundleCompilerInterface $compiler,
32+
private string $dirName,
33+
) {
3734
}
3835

3936
public function generateData(GeneratorConfig $config): void

Data/Generator/GeneratorConfig.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,15 @@
2222
*/
2323
class GeneratorConfig
2424
{
25-
private string $sourceDir;
26-
private string $icuVersion;
27-
2825
/**
2926
* @var BundleWriterInterface[]
3027
*/
3128
private array $bundleWriters = [];
3229

33-
public function __construct(string $sourceDir, string $icuVersion)
34-
{
35-
$this->sourceDir = $sourceDir;
36-
$this->icuVersion = $icuVersion;
30+
public function __construct(
31+
private string $sourceDir,
32+
private string $icuVersion,
33+
) {
3734
}
3835

3936
/**

Data/Generator/RegionDataGenerator.php

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,14 @@ class RegionDataGenerator extends AbstractDataGenerator
5656
'QO' => true, // Outlying Oceania
5757
'XA' => true, // Pseudo-Accents
5858
'XB' => true, // Pseudo-Bidi
59-
'XK' => true, // Kosovo
6059
// Misc
6160
'ZZ' => true, // Unknown Region
6261
];
6362

63+
private const USER_ASSIGNED = [
64+
'XK' => true, // Kosovo
65+
];
66+
6467
// @see https://en.wikipedia.org/wiki/ISO_3166-1_numeric#Withdrawn_codes
6568
private const WITHDRAWN_CODES = [
6669
128, // Canton and Enderbury Islands
@@ -97,7 +100,7 @@ class RegionDataGenerator extends AbstractDataGenerator
97100

98101
public static function isValidCountryCode(int|string|null $region): bool
99102
{
100-
if (isset(self::DENYLIST[$region])) {
103+
if (isset(self::DENYLIST[$region]) || isset(self::USER_ASSIGNED[$region])) {
101104
return false;
102105
}
103106

@@ -109,6 +112,11 @@ public static function isValidCountryCode(int|string|null $region): bool
109112
return true;
110113
}
111114

115+
public static function isUserAssignedCountryCode(int|string|null $region): bool
116+
{
117+
return isset(self::USER_ASSIGNED[$region]);
118+
}
119+
112120
protected function scanLocales(LocaleScanner $scanner, string $sourceDir): array
113121
{
114122
return $scanner->scanLocales($sourceDir.'/region');
@@ -131,9 +139,7 @@ protected function generateDataForLocale(BundleEntryReaderInterface $reader, str
131139

132140
// isset() on \ResourceBundle returns true even if the value is null
133141
if (isset($localeBundle['Countries']) && null !== $localeBundle['Countries']) {
134-
$data = [
135-
'Names' => $this->generateRegionNames($localeBundle),
136-
];
142+
$data = $this->generateRegionNames($localeBundle);
137143

138144
$this->regionCodes = array_merge($this->regionCodes, array_keys($data['Names']));
139145

@@ -153,23 +159,39 @@ protected function generateDataForMeta(BundleEntryReaderInterface $reader, strin
153159
$metadataBundle = $reader->read($tempDir, 'metadata');
154160

155161
$this->regionCodes = array_unique($this->regionCodes);
156-
157162
sort($this->regionCodes);
158163

159164
$alpha2ToAlpha3 = $this->generateAlpha2ToAlpha3Mapping(array_flip($this->regionCodes), $metadataBundle);
165+
$userAssignedAlpha2ToAlpha3 = $this->generateAlpha2ToAlpha3Mapping(self::USER_ASSIGNED, $metadataBundle);
166+
160167
$alpha3ToAlpha2 = array_flip($alpha2ToAlpha3);
161168
asort($alpha3ToAlpha2);
169+
$userAssignedAlpha3toAlpha2 = array_flip($userAssignedAlpha2ToAlpha3);
170+
asort($userAssignedAlpha3toAlpha2);
162171

163172
$alpha2ToNumeric = $this->generateAlpha2ToNumericMapping(array_flip($this->regionCodes), $metadataBundle);
173+
$userAssignedAlpha2ToNumeric = $this->generateAlpha2ToNumericMapping(self::USER_ASSIGNED, $metadataBundle);
174+
164175
$numericToAlpha2 = [];
165176
foreach ($alpha2ToNumeric as $alpha2 => $numeric) {
166177
// Add underscore prefix to force keys with leading zeros to remain as string keys.
167178
$numericToAlpha2['_'.$numeric] = $alpha2;
168179
}
180+
$userAssignedNumericToAlpha2 = [];
181+
foreach ($userAssignedAlpha2ToNumeric as $alpha2 => $numeric) {
182+
// Add underscore prefix to force keys with leading zeros to remain as string keys.
183+
$userAssignedNumericToAlpha2['_'.$numeric] = $alpha2;
184+
}
169185

170186
asort($numericToAlpha2);
187+
asort($userAssignedNumericToAlpha2);
171188

172189
return [
190+
'UserAssignedRegions' => array_keys(self::USER_ASSIGNED),
191+
'UserAssignedAlpha2ToAlpha3' => $userAssignedAlpha2ToAlpha3,
192+
'UserAssignedAlpha3ToAlpha2' => $userAssignedAlpha3toAlpha2,
193+
'UserAssignedAlpha2ToNumeric' => $userAssignedAlpha2ToNumeric,
194+
'UserAssignedNumericToAlpha2' => $userAssignedNumericToAlpha2,
173195
'Regions' => $this->regionCodes,
174196
'Alpha2ToAlpha3' => $alpha2ToAlpha3,
175197
'Alpha3ToAlpha2' => $alpha3ToAlpha2,
@@ -181,14 +203,19 @@ protected function generateDataForMeta(BundleEntryReaderInterface $reader, strin
181203
protected function generateRegionNames(ArrayAccessibleResourceBundle $localeBundle): array
182204
{
183205
$unfilteredRegionNames = iterator_to_array($localeBundle['Countries']);
184-
$regionNames = [];
206+
$regionNames = ['UserAssignedNames' => [], 'Names' => []];
185207

186208
foreach ($unfilteredRegionNames as $region => $regionName) {
187-
if (!self::isValidCountryCode($region)) {
209+
if (!self::isValidCountryCode($region) && !self::isUserAssignedCountryCode($region)) {
188210
continue;
189211
}
190212

191-
$regionNames[$region] = $regionName;
213+
if (self::isUserAssignedCountryCode($region)) {
214+
$regionNames['UserAssignedNames'][$region] = $regionName;
215+
continue;
216+
}
217+
218+
$regionNames['Names'][$region] = $regionName;
192219
}
193220

194221
return $regionNames;
@@ -204,7 +231,9 @@ private function generateAlpha2ToAlpha3Mapping(array $countries, ArrayAccessible
204231
$country = $data['replacement'];
205232

206233
if (2 === \strlen($country) && 3 === \strlen($alias) && 'overlong' === $data['reason']) {
207-
if (isset(self::PREFERRED_ALPHA2_TO_ALPHA3_MAPPING[$country])) {
234+
if (isset($countries[$country]) && self::isUserAssignedCountryCode($country)) {
235+
$alpha2ToAlpha3[$country] = $alias;
236+
} elseif (isset($countries[$country]) && !self::isUserAssignedCountryCode($country) && isset(self::PREFERRED_ALPHA2_TO_ALPHA3_MAPPING[$country])) {
208237
// Validate to prevent typos
209238
if (!isset($aliases[self::PREFERRED_ALPHA2_TO_ALPHA3_MAPPING[$country]])) {
210239
throw new RuntimeException('The statically set three-letter mapping '.self::PREFERRED_ALPHA2_TO_ALPHA3_MAPPING[$country].' for the country code '.$country.' seems to be invalid. Typo?');
@@ -242,7 +271,7 @@ private function generateAlpha2ToNumericMapping(array $countries, ArrayAccessibl
242271
continue;
243272
}
244273

245-
if (\in_array($alias, self::WITHDRAWN_CODES)) {
274+
if (\in_array($alias, self::WITHDRAWN_CODES, true)) {
246275
continue;
247276
}
248277

Data/Generator/TimezoneDataGenerator.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Symfony\Component\Intl\Data\Util\ArrayAccessibleResourceBundle;
1818
use Symfony\Component\Intl\Data\Util\LocaleScanner;
1919
use Symfony\Component\Intl\Exception\MissingResourceException;
20-
use Symfony\Component\Intl\Locale;
2120

2221
/**
2322
* The rule for compiling the zone bundle.
@@ -128,20 +127,16 @@ protected function generateDataForRoot(BundleEntryReaderInterface $reader, strin
128127

129128
protected function generateDataForMeta(BundleEntryReaderInterface $reader, string $tempDir): ?array
130129
{
131-
$rootBundle = $reader->read($tempDir, 'root');
132-
133130
$this->zoneIds = array_unique($this->zoneIds);
134131

135132
sort($this->zoneIds);
136133
ksort($this->zoneToCountryMapping);
137134

138-
$data = [
135+
return [
139136
'Zones' => $this->zoneIds,
140137
'ZoneToCountry' => $this->zoneToCountryMapping,
141138
'CountryToZone' => self::generateCountryToZoneMapping($this->zoneToCountryMapping),
142139
];
143-
144-
return $data;
145140
}
146141

147142
private function generateZones(BundleEntryReaderInterface $reader, string $tempDir, string $locale): array

Data/Util/ArrayAccessibleResourceBundle.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@
2525
*/
2626
class ArrayAccessibleResourceBundle implements \ArrayAccess, \IteratorAggregate, \Countable
2727
{
28-
private \ResourceBundle $bundleImpl;
29-
30-
public function __construct(\ResourceBundle $bundleImpl)
31-
{
32-
$this->bundleImpl = $bundleImpl;
28+
public function __construct(
29+
private \ResourceBundle $bundleImpl,
30+
) {
3331
}
3432

3533
public function get(int|string $offset): mixed

0 commit comments

Comments
 (0)