xref: /webtrees/app/Module/LanguageNorwegianBokmal.php (revision 1270d2767576ed4a83917769b0ee3613e3b010bf)
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\LocaleInterface;
23use Fisharebest\Localization\Locale\LocaleNb;
24use Fisharebest\Webtrees\Encodings\UTF8;
25
26use function mb_substr;
27use function str_starts_with;
28
29/**
30 * Class LanguageNorwegianBokmal.
31 */
32class LanguageNorwegianBokmal extends AbstractModule implements ModuleLanguageInterface
33{
34    use ModuleLanguageTrait;
35
36    /**
37     * Phone-book ordering of letters.
38     *
39     * @return array<int,string>
40     */
41    public function alphabet(): array
42    {
43        return [
44            'A',
45            'B',
46            'C',
47            'D',
48            'E',
49            'F',
50            'G',
51            'H',
52            'I',
53            'J',
54            'K',
55            'L',
56            'M',
57            'N',
58            'O',
59            'P',
60            'Q',
61            'R',
62            'S',
63            'T',
64            'U',
65            'V',
66            'W',
67            'X',
68            'Y',
69            'Z',
70            UTF8::LATIN_CAPITAL_LETTER_AE,
71            UTF8::LATIN_CAPITAL_LETTER_O_WITH_STROKE,
72            UTF8::LATIN_CAPITAL_LETTER_A_WITH_RING_ABOVE,
73        ];
74    }
75
76    /**
77     * Some languages use digraphs and trigraphs.
78     *
79     * @param string $string
80     *
81     * @return string
82     */
83    public function initialLetter(string $string): string
84    {
85        if (str_starts_with($string, 'AA')) {
86            return 'Å';
87        }
88
89        return mb_substr($string, 0, 1);
90    }
91
92    /**
93     * Should this module be enabled when it is first installed?
94     *
95     * @return bool
96     */
97    public function isEnabledByDefault(): bool
98    {
99        return false;
100    }
101
102    /**
103     * @return LocaleInterface
104     */
105    public function locale(): LocaleInterface
106    {
107        return new LocaleNb();
108    }
109
110    /**
111     * Letters with diacritics that are considered distinct letters in this language.
112     *
113     * @return array<string,string>
114     */
115    protected function normalizeExceptions(): array
116    {
117        return [
118            'O' . UTF8::COMBINING_LONG_SOLIDUS_OVERLAY => UTF8::LATIN_CAPITAL_LETTER_O_WITH_STROKE,
119            'A' . UTF8::COMBINING_RING_ABOVE           => UTF8::LATIN_CAPITAL_LETTER_A_WITH_RING_ABOVE,
120            'AA'                                       => UTF8::LATIN_CAPITAL_LETTER_A_WITH_RING_ABOVE,
121            'Aa'                                       => UTF8::LATIN_CAPITAL_LETTER_A_WITH_RING_ABOVE,
122            'o' . UTF8::COMBINING_LONG_SOLIDUS_OVERLAY => UTF8::LATIN_SMALL_LETTER_O_WITH_STROKE,
123            'a' . UTF8::COMBINING_RING_ABOVE           => UTF8::LATIN_SMALL_LETTER_A_WITH_RING_ABOVE,
124            'aa'                                       => UTF8::LATIN_SMALL_LETTER_A_WITH_RING_ABOVE,
125            'aA'                                       => UTF8::LATIN_SMALL_LETTER_A_WITH_RING_ABOVE,
126        ];
127    }
128}
129