@@ -37,6 +37,7 @@ class TimezoneDataGenerator extends AbstractDataGenerator
37
37
private array $ zoneIds = [];
38
38
private array $ zoneToCountryMapping = [];
39
39
private array $ localeAliases = [];
40
+ private array $ ianaMap = [];
40
41
41
42
protected function scanLocales (LocaleScanner $ scanner , string $ sourceDir ): array
42
43
{
@@ -64,8 +65,14 @@ protected function preGenerate(): void
64
65
65
66
protected function generateDataForLocale (BundleEntryReaderInterface $ reader , string $ tempDir , string $ displayLocale ): ?array
66
67
{
68
+ if (!$ this ->ianaMap ) {
69
+ foreach ($ reader ->readEntry ($ tempDir , 'timezoneTypes ' , ['ianaMap ' , 'timezone ' ]) as $ cldr => $ iana ) {
70
+ $ this ->ianaMap [str_replace (': ' , '/ ' , $ cldr )] = $ iana ;
71
+ }
72
+ }
73
+
67
74
if (!$ this ->zoneToCountryMapping ) {
68
- $ this ->zoneToCountryMapping = self :: generateZoneToCountryMapping ($ reader ->read ($ tempDir , 'windowsZones ' ));
75
+ $ this ->zoneToCountryMapping = $ this -> generateZoneToCountryMapping ($ reader ->read ($ tempDir , 'windowsZones ' ));
69
76
}
70
77
71
78
// Don't generate aliases, as they are resolved during runtime
@@ -76,7 +83,7 @@ protected function generateDataForLocale(BundleEntryReaderInterface $reader, str
76
83
77
84
$ localeBundle = $ reader ->read ($ tempDir , $ displayLocale );
78
85
79
- if (!isset ($ localeBundle ['zoneStrings ' ]) || null === $ localeBundle [ ' zoneStrings ' ] ) {
86
+ if (!isset ($ localeBundle ['zoneStrings ' ])) {
80
87
return null ;
81
88
}
82
89
@@ -217,6 +224,10 @@ private function generateZones(BundleEntryReaderInterface $reader, string $tempD
217
224
}
218
225
219
226
$ zones [$ id ] = $ name ;
227
+
228
+ if (isset ($ this ->ianaMap [$ id ])) {
229
+ $ zones [$ this ->ianaMap [$ id ]] = $ name ;
230
+ }
220
231
}
221
232
222
233
return $ zones ;
@@ -237,14 +248,20 @@ private static function generateZoneMetadata(ArrayAccessibleResourceBundle $loca
237
248
return $ metadata ;
238
249
}
239
250
240
- private static function generateZoneToCountryMapping (ArrayAccessibleResourceBundle $ windowsZoneBundle ): array
251
+ private function generateZoneToCountryMapping (ArrayAccessibleResourceBundle $ windowsZoneBundle ): array
241
252
{
242
253
$ mapping = [];
243
254
244
255
foreach ($ windowsZoneBundle ['mapTimezones ' ] as $ zoneInfo ) {
245
256
foreach ($ zoneInfo as $ region => $ zones ) {
246
257
if (RegionDataGenerator::isValidCountryCode ($ region )) {
247
- $ mapping += array_fill_keys (explode (' ' , $ zones ), $ region );
258
+ foreach (explode (' ' , $ zones ) as $ zone ) {
259
+ $ mapping [$ zone ] = $ region ;
260
+
261
+ if (isset ($ this ->ianaMap [$ zone ])) {
262
+ $ mapping [$ this ->ianaMap [$ zone ]] = $ region ;
263
+ }
264
+ }
248
265
}
249
266
}
250
267
}
0 commit comments