-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-locales.php
58 lines (47 loc) · 1.78 KB
/
generate-locales.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
$locales = ResourceBundle::getLocales('');
$prefixes = [];
$prefixTest = [];
foreach ($locales AS $locale) {
$prefix = strtok($locale,'_');
$prefixes[$prefix][] = $locale;
}
$firstDays = [];
$minDays = [];
foreach ($prefixes AS $prefix => $locales) {
$cal = IntlCalendar::createInstance(null, $prefix);
$prefixFirstDayOfWeek = $cal->getFirstDayOfWeek();
$prefixMinimalDaysInFirstWeek = $cal->getMinimalDaysInFirstWeek();
$firstDaysTemp = [];
foreach ($locales AS $locale) {
$cal = IntlCalendar::createInstance(null, $locale);
$firstDayOfWeek = $cal->getFirstDayOfWeek();
$minimalDaysInFirstWeek = $cal->getMinimalDaysInFirstWeek();
$localeKey = str_replace('_', '-', strtolower($locale));
if (
($locale === $prefix || $firstDayOfWeek !== $prefixFirstDayOfWeek) &&
($firstDayOfWeek !== 2 && $prefixFirstDayOfWeek !== 2)
) {
$firstDaysTemp[$firstDayOfWeek][] = $localeKey;
}
if (
($locale === $prefix || $minimalDaysInFirstWeek !== $prefixMinimalDaysInFirstWeek) &&
$minimalDaysInFirstWeek > 1
) {
$minDays[$minimalDaysInFirstWeek][] = $localeKey;
}
}
foreach ($firstDaysTemp AS $day => $locales) {
$firstDays[$day] ??= [];
if (count($firstDaysTemp) === 1) {
if ($day != 2) {
$firstDays[$day][] = $prefix;
}
} else {
$firstDays[$day] = array_merge($firstDays[$day], $locales);
}
}
}
echo 'export const weekStart = '.json_encode($firstDays, JSON_UNESCAPED_SLASHES).';';
echo "\n";
echo 'export const minDaysInFirstWeek = '.json_encode($minDays, JSON_UNESCAPED_SLASHES).';';