xref: /webtrees/app/Module/LanguageHungarian.php (revision 5a8afed46297e8105e3e5a33ce37e6a8e88bc79d)
102086832SGreg Roach<?php
23976b470SGreg Roach
302086832SGreg Roach/**
402086832SGreg Roach * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
602086832SGreg Roach * This program is free software: you can redistribute it and/or modify
702086832SGreg Roach * it under the terms of the GNU General Public License as published by
802086832SGreg Roach * the Free Software Foundation, either version 3 of the License, or
902086832SGreg Roach * (at your option) any later version.
1002086832SGreg Roach * This program is distributed in the hope that it will be useful,
1102086832SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
1202086832SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1302086832SGreg Roach * GNU General Public License for more details.
1402086832SGreg Roach * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
1602086832SGreg Roach */
17fcfa147eSGreg Roach
1802086832SGreg Roachdeclare(strict_types=1);
1902086832SGreg Roach
2002086832SGreg Roachnamespace Fisharebest\Webtrees\Module;
2102086832SGreg Roach
2202086832SGreg Roachuse Fisharebest\Localization\Locale\LocaleHu;
2302086832SGreg Roachuse Fisharebest\Localization\Locale\LocaleInterface;
2452288ec7SGreg Roachuse Fisharebest\Webtrees\Encodings\UTF8;
254a9a6095SGreg Roachuse Illuminate\Database\Query\Builder;
264a9a6095SGreg Roach
274a9a6095SGreg Roachuse function mb_substr;
284a9a6095SGreg Roachuse function str_starts_with;
2902086832SGreg Roach
3002086832SGreg Roach/**
3102086832SGreg Roach * Class LanguageHungarian.
3202086832SGreg Roach */
3302086832SGreg Roachclass LanguageHungarian extends AbstractModule implements ModuleLanguageInterface
3402086832SGreg Roach{
3502086832SGreg Roach    use ModuleLanguageTrait;
3602086832SGreg Roach
3702086832SGreg Roach    /**
384a9a6095SGreg Roach     * Phone-book ordering of letters.
394a9a6095SGreg Roach     *
404a9a6095SGreg Roach     * @return array<int,string>
414a9a6095SGreg Roach     */
424a9a6095SGreg Roach    public function alphabet(): array
434a9a6095SGreg Roach    {
4452288ec7SGreg Roach        return [
4552288ec7SGreg Roach            'A',
4652288ec7SGreg Roach            UTF8::LATIN_CAPITAL_LETTER_A_WITH_ACUTE,
4752288ec7SGreg Roach            'B',
4852288ec7SGreg Roach            'C',
4952288ec7SGreg Roach            'CS',
5052288ec7SGreg Roach            'D',
5152288ec7SGreg Roach            'DZ',
5252288ec7SGreg Roach            'DZS',
5352288ec7SGreg Roach            'E',
5452288ec7SGreg Roach            UTF8::LATIN_CAPITAL_LETTER_E_WITH_ACUTE,
5552288ec7SGreg Roach            'F',
5652288ec7SGreg Roach            'G',
5752288ec7SGreg Roach            'GY',
5852288ec7SGreg Roach            'H',
5952288ec7SGreg Roach            'I',
6052288ec7SGreg Roach            UTF8::LATIN_CAPITAL_LETTER_I_WITH_ACUTE,
6152288ec7SGreg Roach            'J',
6252288ec7SGreg Roach            'K',
6352288ec7SGreg Roach            'L',
6452288ec7SGreg Roach            'LY',
6552288ec7SGreg Roach            'M',
6652288ec7SGreg Roach            'N',
6752288ec7SGreg Roach            'NY',
6852288ec7SGreg Roach            'O',
6952288ec7SGreg Roach            UTF8::LATIN_CAPITAL_LETTER_O_WITH_ACUTE,
7052288ec7SGreg Roach            UTF8::LATIN_CAPITAL_LETTER_O_WITH_DIAERESIS,
7152288ec7SGreg Roach            UTF8::LATIN_CAPITAL_LETTER_O_WITH_DOUBLE_ACUTE,
7252288ec7SGreg Roach            'P',
7352288ec7SGreg Roach            'Q',
7452288ec7SGreg Roach            'R',
7552288ec7SGreg Roach            'S',
7652288ec7SGreg Roach            'SZ',
7752288ec7SGreg Roach            'T',
7852288ec7SGreg Roach            'TY',
7952288ec7SGreg Roach            'U',
8052288ec7SGreg Roach            UTF8::LATIN_CAPITAL_LETTER_U_WITH_ACUTE,
8152288ec7SGreg Roach            UTF8::LATIN_CAPITAL_LETTER_U_WITH_DIAERESIS,
8252288ec7SGreg Roach            UTF8::LATIN_CAPITAL_LETTER_U_WITH_DOUBLE_ACUTE,
8352288ec7SGreg Roach            'V',
8452288ec7SGreg Roach            'W',
8552288ec7SGreg Roach            'X',
8652288ec7SGreg Roach            'Y',
8752288ec7SGreg Roach            'Z',
8852288ec7SGreg Roach            'ZS',
8952288ec7SGreg Roach        ];
904a9a6095SGreg Roach    }
914a9a6095SGreg Roach
924a9a6095SGreg Roach    /**
934a9a6095SGreg Roach     * One of: 'DMY', 'MDY', 'YMD'.
944a9a6095SGreg Roach     *
954a9a6095SGreg Roach     * @return string
964a9a6095SGreg Roach     */
974a9a6095SGreg Roach    public function dateOrder(): string
984a9a6095SGreg Roach    {
994a9a6095SGreg Roach        return 'YMD';
1004a9a6095SGreg Roach    }
1014a9a6095SGreg Roach
1024a9a6095SGreg Roach    /**
1034a9a6095SGreg Roach     * Some languages use digraphs and trigraphs.
1044a9a6095SGreg Roach     *
1054a9a6095SGreg Roach     * @param string $string
1064a9a6095SGreg Roach     *
1074a9a6095SGreg Roach     * @return string
1084a9a6095SGreg Roach     */
1094a9a6095SGreg Roach    public function initialLetter(string $string): string
1104a9a6095SGreg Roach    {
111*7dcc0dd1SGreg Roach        foreach (['CS', 'DZS', 'DZ', 'GY', 'LY', 'NY', 'SZ', 'TY', 'ZS'] as $digraph) {
1124a9a6095SGreg Roach            if (str_starts_with($string, $digraph)) {
1134a9a6095SGreg Roach                return $digraph;
1144a9a6095SGreg Roach            }
1154a9a6095SGreg Roach        }
1164a9a6095SGreg Roach
1174a9a6095SGreg Roach        return mb_substr($string, 0, 1);
1184a9a6095SGreg Roach    }
1194a9a6095SGreg Roach
1204a9a6095SGreg Roach    /**
12102086832SGreg Roach     * @return LocaleInterface
12202086832SGreg Roach     */
12302086832SGreg Roach    public function locale(): LocaleInterface
12402086832SGreg Roach    {
12502086832SGreg Roach        return new LocaleHu();
12602086832SGreg Roach    }
12752288ec7SGreg Roach
12852288ec7SGreg Roach    /**
12952288ec7SGreg Roach     * Letters with diacritics that are considered distinct letters in this language.
13052288ec7SGreg Roach     *
13152288ec7SGreg Roach     * @return array<string,string>
13252288ec7SGreg Roach     */
13352288ec7SGreg Roach    protected function normalizeExceptions(): array
13452288ec7SGreg Roach    {
13552288ec7SGreg Roach        return [
13652288ec7SGreg Roach            'A' . UTF8::COMBINING_ACUTE_ACCENT        => UTF8::LATIN_CAPITAL_LETTER_A_WITH_ACUTE,
13752288ec7SGreg Roach            'E' . UTF8::COMBINING_ACUTE_ACCENT        => UTF8::LATIN_CAPITAL_LETTER_E_WITH_ACUTE,
13852288ec7SGreg Roach            'I' . UTF8::COMBINING_ACUTE_ACCENT        => UTF8::LATIN_CAPITAL_LETTER_I_WITH_ACUTE,
13952288ec7SGreg Roach            'O' . UTF8::COMBINING_ACUTE_ACCENT        => UTF8::LATIN_CAPITAL_LETTER_O_WITH_ACUTE,
14052288ec7SGreg Roach            'O' . UTF8::COMBINING_DIAERESIS           => UTF8::LATIN_CAPITAL_LETTER_O_WITH_DIAERESIS,
14152288ec7SGreg Roach            'O' . UTF8::COMBINING_DOUBLE_ACUTE_ACCENT => UTF8::LATIN_CAPITAL_LETTER_O_WITH_DOUBLE_ACUTE,
14252288ec7SGreg Roach            'U' . UTF8::COMBINING_ACUTE_ACCENT        => UTF8::LATIN_CAPITAL_LETTER_U_WITH_ACUTE,
14352288ec7SGreg Roach            'U' . UTF8::COMBINING_DIAERESIS           => UTF8::LATIN_CAPITAL_LETTER_U_WITH_DIAERESIS,
14452288ec7SGreg Roach            'U' . UTF8::COMBINING_DOUBLE_ACUTE_ACCENT => UTF8::LATIN_CAPITAL_LETTER_U_WITH_DOUBLE_ACUTE,
14552288ec7SGreg Roach            'a' . UTF8::COMBINING_ACUTE_ACCENT        => UTF8::LATIN_SMALL_LETTER_A_WITH_ACUTE,
14652288ec7SGreg Roach            'e' . UTF8::COMBINING_ACUTE_ACCENT        => UTF8::LATIN_SMALL_LETTER_E_WITH_ACUTE,
14752288ec7SGreg Roach            'i' . UTF8::COMBINING_ACUTE_ACCENT        => UTF8::LATIN_SMALL_LETTER_I_WITH_ACUTE,
14852288ec7SGreg Roach            'o' . UTF8::COMBINING_ACUTE_ACCENT        => UTF8::LATIN_SMALL_LETTER_O_WITH_ACUTE,
14952288ec7SGreg Roach            'o' . UTF8::COMBINING_DIAERESIS           => UTF8::LATIN_SMALL_LETTER_O_WITH_DIAERESIS,
15052288ec7SGreg Roach            'o' . UTF8::COMBINING_DOUBLE_ACUTE_ACCENT => UTF8::LATIN_SMALL_LETTER_O_WITH_DOUBLE_ACUTE,
15152288ec7SGreg Roach            'u' . UTF8::COMBINING_ACUTE_ACCENT        => UTF8::LATIN_SMALL_LETTER_U_WITH_ACUTE,
15252288ec7SGreg Roach            'u' . UTF8::COMBINING_DIAERESIS           => UTF8::LATIN_SMALL_LETTER_U_WITH_DIAERESIS,
15352288ec7SGreg Roach            'u' . UTF8::COMBINING_DOUBLE_ACUTE_ACCENT => UTF8::LATIN_SMALL_LETTER_U_WITH_DOUBLE_ACUTE,
15452288ec7SGreg Roach        ];
15552288ec7SGreg Roach    }
15602086832SGreg Roach}
157