xref: /webtrees/app/Module/LanguageCzech.php (revision b11cdcd45131b1585d66693fab363cfeb18c51a4)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * 'Copyright (C) 2023 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Module;
21
22use Fisharebest\Localization\Locale\LocaleCs;
23use Fisharebest\Localization\Locale\LocaleInterface;
24use Fisharebest\Webtrees\Encodings\UTF8;
25use Illuminate\Database\Query\Builder;
26
27use function mb_substr;
28use function str_starts_with;
29
30/**
31 * Class LanguageCzech.
32 */
33class LanguageCzech extends AbstractModule implements ModuleLanguageInterface
34{
35    use ModuleLanguageTrait;
36
37    /**
38     * Phone-book ordering of letters.
39     *
40     * @return array<int,string>
41     */
42    public function alphabet(): array
43    {
44        return [
45            'A',
46            UTF8::LATIN_CAPITAL_LETTER_A_WITH_ACUTE,
47            'B',
48            'C',
49            UTF8::LATIN_CAPITAL_LETTER_C_WITH_CARON,
50            'D',
51            UTF8::LATIN_CAPITAL_LETTER_D_WITH_CARON,
52            'E',
53            UTF8::LATIN_CAPITAL_LETTER_E_WITH_ACUTE,
54            UTF8::LATIN_CAPITAL_LETTER_E_WITH_CARON,
55            'F',
56            'G',
57            'H',
58            'CH',
59            'I',
60            UTF8::LATIN_CAPITAL_LETTER_I_WITH_ACUTE,
61            'J',
62            'K',
63            'L',
64            'M',
65            'N',
66            UTF8::LATIN_CAPITAL_LETTER_N_WITH_CARON,
67            'O',
68            UTF8::LATIN_CAPITAL_LETTER_O_WITH_ACUTE,
69            'P',
70            'Q',
71            'R',
72            UTF8::LATIN_CAPITAL_LETTER_R_WITH_CARON,
73            'S',
74            UTF8::LATIN_CAPITAL_LETTER_S_WITH_CARON,
75            'T',
76            UTF8::LATIN_CAPITAL_LETTER_T_WITH_CARON,
77            'U',
78            UTF8::LATIN_CAPITAL_LETTER_U_WITH_ACUTE,
79            UTF8::LATIN_CAPITAL_LETTER_U_WITH_RING_ABOVE,
80            'V',
81            'W',
82            'X',
83            'Y',
84            UTF8::LATIN_CAPITAL_LETTER_Y_WITH_ACUTE,
85            'Z',
86            UTF8::LATIN_CAPITAL_LETTER_Z_WITH_CARON,
87        ];
88    }
89
90    /**
91     * Some languages use digraphs and trigraphs.
92     *
93     * @param string $string
94     *
95     * @return string
96     */
97    public function initialLetter(string $string): string
98    {
99        if (str_starts_with($string, 'CS')) {
100            return 'CS';
101        }
102
103        return mb_substr($string, 0, 1);
104    }
105
106    /**
107     * @return LocaleInterface
108     */
109    public function locale(): LocaleInterface
110    {
111        return new LocaleCs();
112    }
113
114    /**
115     * Letters with diacritics that are considered distinct letters in this language.
116     *
117     * @return array<string,string>
118     */
119    protected function normalizeExceptions(): array
120    {
121        return [
122            'A' . UTF8::COMBINING_CARON        => UTF8::LATIN_CAPITAL_LETTER_A_WITH_ACUTE,
123            'C' . UTF8::COMBINING_CARON        => UTF8::LATIN_CAPITAL_LETTER_C_WITH_CARON,
124            'D' . UTF8::COMBINING_CARON        => UTF8::LATIN_CAPITAL_LETTER_D_WITH_CARON,
125            'E' . UTF8::COMBINING_ACUTE_ACCENT => UTF8::LATIN_CAPITAL_LETTER_E_WITH_ACUTE,
126            'E' . UTF8::COMBINING_CARON        => UTF8::LATIN_CAPITAL_LETTER_E_WITH_CARON,
127            'I' . UTF8::COMBINING_ACUTE_ACCENT => UTF8::LATIN_CAPITAL_LETTER_I_WITH_ACUTE,
128            'N' . UTF8::COMBINING_CARON        => UTF8::LATIN_CAPITAL_LETTER_N_WITH_CARON,
129            'O' . UTF8::COMBINING_ACUTE_ACCENT => UTF8::LATIN_CAPITAL_LETTER_O_WITH_ACUTE,
130            'R' . UTF8::COMBINING_CARON        => UTF8::LATIN_CAPITAL_LETTER_R_WITH_CARON,
131            'S' . UTF8::COMBINING_CARON        => UTF8::LATIN_CAPITAL_LETTER_S_WITH_CARON,
132            'T' . UTF8::COMBINING_CARON        => UTF8::LATIN_CAPITAL_LETTER_T_WITH_CARON,
133            'U' . UTF8::COMBINING_ACUTE_ACCENT => UTF8::LATIN_CAPITAL_LETTER_U_WITH_ACUTE,
134            'U' . UTF8::COMBINING_CARON        => UTF8::LATIN_CAPITAL_LETTER_U_WITH_RING_ABOVE,
135            'Y' . UTF8::COMBINING_ACUTE_ACCENT => UTF8::LATIN_CAPITAL_LETTER_Y_WITH_ACUTE,
136            'Z' . UTF8::COMBINING_CARON        => UTF8::LATIN_CAPITAL_LETTER_Z_WITH_CARON,
137            'a' . UTF8::COMBINING_CARON        => UTF8::LATIN_SMALL_LETTER_A_WITH_ACUTE,
138            'c' . UTF8::COMBINING_CARON        => UTF8::LATIN_SMALL_LETTER_C_WITH_CARON,
139            'd' . UTF8::COMBINING_CARON        => UTF8::LATIN_SMALL_LETTER_D_WITH_CARON,
140            'e' . UTF8::COMBINING_ACUTE_ACCENT => UTF8::LATIN_SMALL_LETTER_E_WITH_ACUTE,
141            'e' . UTF8::COMBINING_CARON        => UTF8::LATIN_SMALL_LETTER_E_WITH_CARON,
142            'i' . UTF8::COMBINING_ACUTE_ACCENT => UTF8::LATIN_SMALL_LETTER_I_WITH_ACUTE,
143            'n' . UTF8::COMBINING_CARON        => UTF8::LATIN_SMALL_LETTER_N_WITH_CARON,
144            'o' . UTF8::COMBINING_ACUTE_ACCENT => UTF8::LATIN_SMALL_LETTER_O_WITH_ACUTE,
145            'r' . UTF8::COMBINING_CARON        => UTF8::LATIN_SMALL_LETTER_R_WITH_CARON,
146            's' . UTF8::COMBINING_CARON        => UTF8::LATIN_SMALL_LETTER_S_WITH_CARON,
147            't' . UTF8::COMBINING_CARON        => UTF8::LATIN_SMALL_LETTER_T_WITH_CARON,
148            'u' . UTF8::COMBINING_ACUTE_ACCENT => UTF8::LATIN_SMALL_LETTER_U_WITH_ACUTE,
149            'u' . UTF8::COMBINING_CARON        => UTF8::LATIN_SMALL_LETTER_U_WITH_RING_ABOVE,
150            'y' . UTF8::COMBINING_ACUTE_ACCENT => UTF8::LATIN_SMALL_LETTER_Y_WITH_ACUTE,
151            'z' . UTF8::COMBINING_CARON        => UTF8::LATIN_SMALL_LETTER_Z_WITH_CARON,
152        ];
153    }
154}
155