xref: /webtrees/app/Module/ModuleLanguageTrait.php (revision 4a9a60957058ca2a34e30a0d6f783e1540606590)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2022 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\ExtCalendar\CalendarInterface;
23use Fisharebest\ExtCalendar\GregorianCalendar;
24use Fisharebest\Localization\Locale\LocaleEnUs;
25use Fisharebest\Localization\Locale\LocaleInterface;
26use Fisharebest\Webtrees\I18N;
27use Fisharebest\Webtrees\Relationship;
28use Illuminate\Database\Query\Builder;
29
30use function mb_substr;
31
32/**
33 * Trait ModuleLanguageEventsTrait - default implementation of ModuleLanguageInterface.
34 */
35trait ModuleLanguageTrait
36{
37    /**
38     * Phone-book ordering of letters.
39     *
40     * @return array<int,string>
41     */
42    public function alphabet(): array
43    {
44        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    }
46
47    /**
48     * Default calendar used by this language.
49     *
50     * @return CalendarInterface
51     */
52    public function calendar(): CalendarInterface
53    {
54        return new GregorianCalendar();
55    }
56
57    /**
58     * One of: 'DMY', 'MDY', 'YMD'.
59     *
60     * @return string
61     */
62    public function dateOrder(): string
63    {
64        return 'DMY';
65    }
66
67    /**
68     * Some languages treat certain letter-combinations as equivalent.
69     *
70     * @return array<string,string>
71     */
72    public function equivalentLetters(): array
73    {
74        return [];
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        return mb_substr($string, 0, 1);
87    }
88
89    /**
90     * @param string  $column
91     * @param string  $letter
92     * @param Builder $query
93     *
94     * @return void
95     */
96    public function initialLetterSQL(string $column, string $letter, Builder $query): void
97    {
98        $query->where($column, 'LIKE', '\\' . $letter . '%');
99    }
100
101    /**
102     * How should this module be identified in the control panel, etc.?
103     *
104     * @return string
105     */
106    public function title(): string
107    {
108        return  $this->locale()->endonym();
109    }
110
111    /**
112     * A sentence describing what this module does.
113     *
114     * @return string
115     */
116    public function description(): string
117    {
118        return I18N::translate('Language') . ' — ' . $this->title() . ' — ' . $this->locale()->languageTag();
119    }
120
121    /**
122     * @return LocaleInterface
123     */
124    public function locale(): LocaleInterface
125    {
126        return new LocaleEnUs();
127    }
128
129    /**
130     * @return array<Relationship>
131     */
132    public function relationships(): array
133    {
134        return [];
135    }
136}
137