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