Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dca6a05

Browse files
committed
Add time zone translations
1 parent 368a0c3 commit dca6a05

Some content is hidden

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

52 files changed

+76103
-8
lines changed

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* added `input=datetime_immutable` to DateType, TimeType, DateTimeType
88
* added `rounding_mode` option to MoneyType
9+
* added translations for TimezoneType
910

1011
4.0.0
1112
-----

src/Symfony/Component/Form/Extension/Core/Type/TimezoneType.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function configureOptions(OptionsResolver $resolver)
4343
return self::getTimezones($regions);
4444
});
4545
},
46-
'choice_translation_domain' => false,
46+
'choice_translation_domain' => 'timezone',
4747
'input' => 'string',
4848
'regions' => \DateTimeZone::ALL,
4949
));
@@ -71,8 +71,11 @@ public function getBlockPrefix()
7171

7272
/**
7373
* Returns a normalized array of timezone choices.
74+
*
75+
* This function is not part of the public API but should only be called
76+
* from update-timezone-translations.php.
7477
*/
75-
private static function getTimezones(int $regions): array
78+
public static function getTimezones(int $regions): array
7679
{
7780
$timezones = array();
7881

@@ -81,7 +84,7 @@ private static function getTimezones(int $regions): array
8184

8285
if (count($parts) > 2) {
8386
$region = $parts[0];
84-
$name = $parts[1].' - '.$parts[2];
87+
$name = $parts[2].', '.$parts[1];
8588
} elseif (count($parts) > 1) {
8689
$region = $parts[0];
8790
$name = $parts[1];
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
/*
5+
* This file is part of the Symfony package.
6+
*
7+
* (c) Fabien Potencier <[email protected]>
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
13+
/**
14+
* Generates translation files for use in TimezoneType based on the Unicode
15+
* Common Locale Data Repository.
16+
*
17+
* The generates files are written to Resources/translations and should be
18+
* committed to Git.
19+
*/
20+
$componentDir = realpath(__DIR__.'/../..');
21+
$autoloadFile = $componentDir.'/vendor/autoload.php';
22+
23+
if (!is_file($autoloadFile)) {
24+
die("$autoloadFile not found; run `composer update` in $componentDir.\n");
25+
}
26+
27+
require_once $autoloadFile;
28+
29+
use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
30+
use Symfony\Component\Translation\Dumper\XliffFileDumper;
31+
use Symfony\Component\Translation\MessageCatalogue;
32+
33+
// We only support a small subset of the many locales included in CLDR.
34+
$locales = array(
35+
'ar' => 'ar',
36+
'az' => 'az',
37+
'bg' => 'bg',
38+
'ca' => 'ca',
39+
'cs' => 'cs',
40+
'da' => 'da',
41+
'de' => 'de',
42+
'el' => 'el',
43+
'en' => 'en',
44+
'es' => 'es',
45+
'et' => 'et',
46+
'eu' => 'eu',
47+
'fa' => 'fa',
48+
'fi' => 'fi',
49+
'fr' => 'fr',
50+
'gl' => 'gl',
51+
'he' => 'he',
52+
'hr' => 'hr',
53+
'hu' => 'hu',
54+
'hy' => 'hy',
55+
'id' => 'id',
56+
'it' => 'it',
57+
'ja' => 'ja',
58+
'lb' => 'lb',
59+
'lt' => 'lt',
60+
'lv' => 'lv',
61+
'mn' => 'mn',
62+
'nb' => 'nb',
63+
'nl' => 'nl',
64+
'nn' => 'nn',
65+
'no' => 'no',
66+
'pl' => 'pl',
67+
'pt' => 'pt',
68+
'pt_BR' => 'pt_BR',
69+
'ro' => 'ro',
70+
'ru' => 'ru',
71+
'sk' => 'sk',
72+
'sl' => 'sl',
73+
'sr_Cyrl' => 'sr',
74+
'sr_Latn' => 'sr_Latn',
75+
'sv' => 'sv',
76+
'tl' => 'tl',
77+
'uk' => 'uk',
78+
'zh_CN' => 'zh_Hans_CN',
79+
);
80+
81+
// Timezone identifiers containing 2 slashes need a qualifier in addition to
82+
// just the city name. E.g. America/Argentina/San_Juan needs to be distinguished
83+
// from other cities named San Juan. On the other hand, for US states the CLDR
84+
// string already contains the qualifier, e.g. the English string fo
85+
// America/Indiana/Knox is "Knox, Indiana".
86+
$countries = array(
87+
'America/Argentina' => 'AR',
88+
'America/Indiana' => false,
89+
'America/Kentucky' => false,
90+
'America/North_Dakota' => false,
91+
);
92+
93+
// Not all tzdata areas (the string before the first slash) correspond to
94+
// territories definded in CLDR.
95+
$areas = array(
96+
'America' => '019',
97+
'Africa' => '002',
98+
'Antarctica' => 'AQ',
99+
'Arctic' => false,
100+
'Asia' => '142',
101+
'Atlantic' => false,
102+
'Australia' => '053',
103+
'Europe' => '150',
104+
'Indian' => false,
105+
'Pacific' => false,
106+
'Other' => false,
107+
);
108+
109+
$options = array(
110+
'path' => $componentDir.'/Resources/translations/generated',
111+
'default_locale' => 'en',
112+
'tool_info' => array(
113+
'tool-id' => basename(__FILE__),
114+
'tool-name' => 'CLDR time zone translation generator',
115+
),
116+
);
117+
118+
$timezones = TimezoneType::getTimezones(\DateTimeZone::ALL);
119+
120+
$domain = 'timezones';
121+
122+
$identifiers = \DateTimeZone::listIdentifiers(\DateTimeZone::ALL_WITH_BC);
123+
124+
foreach ($locales as $locale => $cldrLocale) {
125+
$names = array();
126+
127+
foreach ($timezones as $area => $identifiers) {
128+
if (!isset($areas[$area])) {
129+
die("Area $area not \$areas.\n");
130+
}
131+
if ($areas[$area]) {
132+
$areaName = Punic\Territory::getName($areas[$area], $cldrLocale);
133+
if ($areaName) {
134+
$names[$area] = $areaName;
135+
}
136+
}
137+
138+
foreach ($identifiers as $key => $identifier) {
139+
$timezoneName = Punic\Calendar::getTimezoneExemplarCity($identifier, false, $cldrLocale);
140+
141+
$parts = explode('/', $identifier);
142+
if (count($parts) >= 3) {
143+
$prefix = $parts[0].'/'.$parts[1];
144+
if (!isset($countries[$prefix])) {
145+
die("Prefix $prefix not defined in \$countries.\n");
146+
}
147+
if ($countries[$prefix]) {
148+
$countryName = Punic\Territory::getName($countries[$prefix], $cldrLocale);
149+
$timezoneName .= ', '.$countryName;
150+
}
151+
}
152+
153+
if ($timezoneName) {
154+
$names[$key] = $timezoneName;
155+
}
156+
}
157+
}
158+
159+
$catalogue = new MessageCatalogue($locale);
160+
$catalogue->add($names, $domain);
161+
162+
$dumper = new XliffFileDumper();
163+
$dumper->dump($catalogue, $options);
164+
}

0 commit comments

Comments
 (0)