xref: /webtrees/app/Module/ModuleLanguageTrait.php (revision 4a9a60957058ca2a34e30a0d6f783e1540606590)
111eb8581SGreg Roach<?php
23976b470SGreg Roach
311eb8581SGreg Roach/**
411eb8581SGreg Roach * webtrees: online genealogy
55bfc6897SGreg Roach * Copyright (C) 2022 webtrees development team
611eb8581SGreg Roach * This program is free software: you can redistribute it and/or modify
711eb8581SGreg Roach * it under the terms of the GNU General Public License as published by
811eb8581SGreg Roach * the Free Software Foundation, either version 3 of the License, or
911eb8581SGreg Roach * (at your option) any later version.
1011eb8581SGreg Roach * This program is distributed in the hope that it will be useful,
1111eb8581SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
1211eb8581SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1311eb8581SGreg Roach * GNU General Public License for more details.
1411eb8581SGreg 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/>.
1611eb8581SGreg Roach */
17fcfa147eSGreg Roach
1811eb8581SGreg Roachdeclare(strict_types=1);
1911eb8581SGreg Roach
2011eb8581SGreg Roachnamespace Fisharebest\Webtrees\Module;
2111eb8581SGreg Roach
22*4a9a6095SGreg Roachuse Fisharebest\ExtCalendar\CalendarInterface;
23*4a9a6095SGreg Roachuse Fisharebest\ExtCalendar\GregorianCalendar;
2402086832SGreg Roachuse Fisharebest\Localization\Locale\LocaleEnUs;
2502086832SGreg Roachuse Fisharebest\Localization\Locale\LocaleInterface;
263d8b2a8eSGreg Roachuse Fisharebest\Webtrees\I18N;
276fcafd02SGreg Roachuse Fisharebest\Webtrees\Relationship;
28*4a9a6095SGreg Roachuse Illuminate\Database\Query\Builder;
29*4a9a6095SGreg Roach
30*4a9a6095SGreg Roachuse function mb_substr;
3102086832SGreg Roach
3211eb8581SGreg Roach/**
3311eb8581SGreg Roach * Trait ModuleLanguageEventsTrait - default implementation of ModuleLanguageInterface.
3411eb8581SGreg Roach */
3511eb8581SGreg Roachtrait ModuleLanguageTrait
3611eb8581SGreg Roach{
373d8b2a8eSGreg Roach    /**
38*4a9a6095SGreg Roach     * Phone-book ordering of letters.
39*4a9a6095SGreg Roach     *
40*4a9a6095SGreg Roach     * @return array<int,string>
41*4a9a6095SGreg Roach     */
42*4a9a6095SGreg Roach    public function alphabet(): array
43*4a9a6095SGreg Roach    {
44*4a9a6095SGreg Roach        return ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
45*4a9a6095SGreg Roach    }
46*4a9a6095SGreg Roach
47*4a9a6095SGreg Roach    /**
48*4a9a6095SGreg Roach     * Default calendar used by this language.
49*4a9a6095SGreg Roach     *
50*4a9a6095SGreg Roach     * @return CalendarInterface
51*4a9a6095SGreg Roach     */
52*4a9a6095SGreg Roach    public function calendar(): CalendarInterface
53*4a9a6095SGreg Roach    {
54*4a9a6095SGreg Roach        return new GregorianCalendar();
55*4a9a6095SGreg Roach    }
56*4a9a6095SGreg Roach
57*4a9a6095SGreg Roach    /**
58*4a9a6095SGreg Roach     * One of: 'DMY', 'MDY', 'YMD'.
59*4a9a6095SGreg Roach     *
60*4a9a6095SGreg Roach     * @return string
61*4a9a6095SGreg Roach     */
62*4a9a6095SGreg Roach    public function dateOrder(): string
63*4a9a6095SGreg Roach    {
64*4a9a6095SGreg Roach        return 'DMY';
65*4a9a6095SGreg Roach    }
66*4a9a6095SGreg Roach
67*4a9a6095SGreg Roach    /**
68*4a9a6095SGreg Roach     * Some languages treat certain letter-combinations as equivalent.
69*4a9a6095SGreg Roach     *
70*4a9a6095SGreg Roach     * @return array<string,string>
71*4a9a6095SGreg Roach     */
72*4a9a6095SGreg Roach    public function equivalentLetters(): array
73*4a9a6095SGreg Roach    {
74*4a9a6095SGreg Roach        return [];
75*4a9a6095SGreg Roach    }
76*4a9a6095SGreg Roach
77*4a9a6095SGreg Roach    /**
78*4a9a6095SGreg Roach     * Some languages use digraphs and trigraphs.
79*4a9a6095SGreg Roach     *
80*4a9a6095SGreg Roach     * @param string $string
81*4a9a6095SGreg Roach     *
82*4a9a6095SGreg Roach     * @return string
83*4a9a6095SGreg Roach     */
84*4a9a6095SGreg Roach    public function initialLetter(string $string): string
85*4a9a6095SGreg Roach    {
86*4a9a6095SGreg Roach        return mb_substr($string, 0, 1);
87*4a9a6095SGreg Roach    }
88*4a9a6095SGreg Roach
89*4a9a6095SGreg Roach    /**
90*4a9a6095SGreg Roach     * @param string  $column
91*4a9a6095SGreg Roach     * @param string  $letter
92*4a9a6095SGreg Roach     * @param Builder $query
93*4a9a6095SGreg Roach     *
94*4a9a6095SGreg Roach     * @return void
95*4a9a6095SGreg Roach     */
96*4a9a6095SGreg Roach    public function initialLetterSQL(string $column, string $letter, Builder $query): void
97*4a9a6095SGreg Roach    {
98*4a9a6095SGreg Roach        $query->where($column, 'LIKE', '\\' . $letter . '%');
99*4a9a6095SGreg Roach    }
100*4a9a6095SGreg Roach
101*4a9a6095SGreg Roach    /**
1023d8b2a8eSGreg Roach     * How should this module be identified in the control panel, etc.?
1033d8b2a8eSGreg Roach     *
1043d8b2a8eSGreg Roach     * @return string
1053d8b2a8eSGreg Roach     */
10602086832SGreg Roach    public function title(): string
10702086832SGreg Roach    {
10802086832SGreg Roach        return  $this->locale()->endonym();
10902086832SGreg Roach    }
11002086832SGreg Roach
1113d8b2a8eSGreg Roach    /**
1123d8b2a8eSGreg Roach     * A sentence describing what this module does.
1133d8b2a8eSGreg Roach     *
1143d8b2a8eSGreg Roach     * @return string
1153d8b2a8eSGreg Roach     */
11602086832SGreg Roach    public function description(): string
11702086832SGreg Roach    {
1183d8b2a8eSGreg Roach        return I18N::translate('Language') . ' — ' . $this->title() . ' — ' . $this->locale()->languageTag();
11902086832SGreg Roach    }
12002086832SGreg Roach
12102086832SGreg Roach    /**
12202086832SGreg Roach     * @return LocaleInterface
12302086832SGreg Roach     */
12402086832SGreg Roach    public function locale(): LocaleInterface
12502086832SGreg Roach    {
12602086832SGreg Roach        return new LocaleEnUs();
12702086832SGreg Roach    }
1286fcafd02SGreg Roach
1296fcafd02SGreg Roach    /**
1306fcafd02SGreg Roach     * @return array<Relationship>
1316fcafd02SGreg Roach     */
1326fcafd02SGreg Roach    public function relationships(): array
1336fcafd02SGreg Roach    {
1346fcafd02SGreg Roach        return [];
1356fcafd02SGreg Roach    }
13611eb8581SGreg Roach}
137