xref: /webtrees/app/Module/LanguageDanish.php (revision d11be7027e34e3121be11cc025421873364403f9)
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\LocaleDa;
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 LanguageDanish.
32 */
33class LanguageDanish 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            'B',
47            'C',
48            'D',
49            'E',
50            'F',
51            'G',
52            'H',
53            'I',
54            'J',
55            'K',
56            'L',
57            'M',
58            'N',
59            'O',
60            'P',
61            'Q',
62            'R',
63            'S',
64            'T',
65            'U',
66            'V',
67            'W',
68            'X',
69            'Y',
70            'Z',
71            UTF8::LATIN_CAPITAL_LETTER_AE,
72            UTF8::LATIN_CAPITAL_LETTER_O_WITH_STROKE,
73            UTF8::LATIN_CAPITAL_LETTER_A_WITH_RING_ABOVE,
74        ];
75    }
76
77    /**
78     * Some languages use digraphs and trigraphs.
79     *
80     * @param string $string
81     *
82     * @return string
83     */
84    public function initialLetter(string $string): string
85    {
86        if (str_starts_with($string, 'AA')) {
87            return 'Å';
88        }
89
90        return mb_substr($string, 0, 1);
91    }
92
93    /**
94     * @return LocaleInterface
95     */
96    public function locale(): LocaleInterface
97    {
98        return new LocaleDa();
99    }
100
101    /**
102     * Letters with diacritics that are considered distinct letters in this language.
103     *
104     * @return array<string,string>
105     */
106    protected function normalizeExceptions(): array
107    {
108        return [
109            'A' . UTF8::COMBINING_RING_ABOVE           => UTF8::LATIN_CAPITAL_LETTER_A_WITH_RING_ABOVE,
110            'AA'                                       => UTF8::LATIN_CAPITAL_LETTER_A_WITH_RING_ABOVE,
111            'AE'                                       => UTF8::LATIN_CAPITAL_LETTER_AE,
112            'Aa'                                       => UTF8::LATIN_CAPITAL_LETTER_A_WITH_RING_ABOVE,
113            'O' . UTF8::COMBINING_LONG_SOLIDUS_OVERLAY => UTF8::LATIN_CAPITAL_LETTER_O_WITH_STROKE,
114            'a' . UTF8::COMBINING_RING_ABOVE           => UTF8::LATIN_SMALL_LETTER_A_WITH_RING_ABOVE,
115            'aA'                                       => UTF8::LATIN_SMALL_LETTER_A_WITH_RING_ABOVE,
116            'aa'                                       => UTF8::LATIN_SMALL_LETTER_A_WITH_RING_ABOVE,
117            'ae'                                       => UTF8::LATIN_SMALL_LETTER_AE,
118            'o' . UTF8::COMBINING_LONG_SOLIDUS_OVERLAY => UTF8::LATIN_SMALL_LETTER_O_WITH_STROKE,
119        ];
120    }
121}
122