xref: /webtrees/app/Elements/LanguageId.php (revision 2ebcf907ed34213f816592af04e6c160335d6311)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2021 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\Elements;
21
22use Fisharebest\Localization\Locale\LocaleAf;
23use Fisharebest\Localization\Locale\LocaleAm;
24use Fisharebest\Localization\Locale\LocaleAng;
25use Fisharebest\Localization\Locale\LocaleAr;
26use Fisharebest\Localization\Locale\LocaleAs;
27use Fisharebest\Localization\Locale\LocaleBe;
28use Fisharebest\Localization\Locale\LocaleBg;
29use Fisharebest\Localization\Locale\LocaleBn;
30use Fisharebest\Localization\Locale\LocaleBo;
31use Fisharebest\Localization\Locale\LocaleCa;
32use Fisharebest\Localization\Locale\LocaleCaEsValencia;
33use Fisharebest\Localization\Locale\LocaleCs;
34use Fisharebest\Localization\Locale\LocaleCu;
35use Fisharebest\Localization\Locale\LocaleDa;
36use Fisharebest\Localization\Locale\LocaleDe;
37use Fisharebest\Localization\Locale\LocaleEl;
38use Fisharebest\Localization\Locale\LocaleEn;
39use Fisharebest\Localization\Locale\LocaleEo;
40use Fisharebest\Localization\Locale\LocaleEs;
41use Fisharebest\Localization\Locale\LocaleEt;
42use Fisharebest\Localization\Locale\LocaleFa;
43use Fisharebest\Localization\Locale\LocaleFi;
44use Fisharebest\Localization\Locale\LocaleFo;
45use Fisharebest\Localization\Locale\LocaleFr;
46use Fisharebest\Localization\Locale\LocaleGu;
47use Fisharebest\Localization\Locale\LocaleHaw;
48use Fisharebest\Localization\Locale\LocaleHe;
49use Fisharebest\Localization\Locale\LocaleHi;
50use Fisharebest\Localization\Locale\LocaleHu;
51use Fisharebest\Localization\Locale\LocaleHy;
52use Fisharebest\Localization\Locale\LocaleId;
53use Fisharebest\Localization\Locale\LocaleIs;
54use Fisharebest\Localization\Locale\LocaleIt;
55use Fisharebest\Localization\Locale\LocaleJa;
56use Fisharebest\Localization\Locale\LocaleKa;
57use Fisharebest\Localization\Locale\LocaleKm;
58use Fisharebest\Localization\Locale\LocaleKn;
59use Fisharebest\Localization\Locale\LocaleKo;
60use Fisharebest\Localization\Locale\LocaleKok;
61use Fisharebest\Localization\Locale\LocaleLo;
62use Fisharebest\Localization\Locale\LocaleLt;
63use Fisharebest\Localization\Locale\LocaleLv;
64use Fisharebest\Localization\Locale\LocaleMk;
65use Fisharebest\Localization\Locale\LocaleMl;
66use Fisharebest\Localization\Locale\LocaleMr;
67use Fisharebest\Localization\Locale\LocaleMy;
68use Fisharebest\Localization\Locale\LocaleNe;
69use Fisharebest\Localization\Locale\LocaleNl;
70use Fisharebest\Localization\Locale\LocaleNn;
71use Fisharebest\Localization\Locale\LocaleOr;
72use Fisharebest\Localization\Locale\LocalePa;
73use Fisharebest\Localization\Locale\LocalePl;
74use Fisharebest\Localization\Locale\LocalePs;
75use Fisharebest\Localization\Locale\LocalePt;
76use Fisharebest\Localization\Locale\LocaleRo;
77use Fisharebest\Localization\Locale\LocaleRu;
78use Fisharebest\Localization\Locale\LocaleSk;
79use Fisharebest\Localization\Locale\LocaleSl;
80use Fisharebest\Localization\Locale\LocaleSq;
81use Fisharebest\Localization\Locale\LocaleSr;
82use Fisharebest\Localization\Locale\LocaleSv;
83use Fisharebest\Localization\Locale\LocaleTa;
84use Fisharebest\Localization\Locale\LocaleTe;
85use Fisharebest\Localization\Locale\LocaleTh;
86use Fisharebest\Localization\Locale\LocaleTl;
87use Fisharebest\Localization\Locale\LocaleTr;
88use Fisharebest\Localization\Locale\LocaleUk;
89use Fisharebest\Localization\Locale\LocaleUr;
90use Fisharebest\Localization\Locale\LocaleVi;
91use Fisharebest\Localization\Locale\LocaleYi;
92use Fisharebest\Localization\Locale\LocaleYue;
93use Fisharebest\Webtrees\I18N;
94
95use function preg_replace_callback;
96
97/**
98 * LANGUAGE_ID := {Size=1:15}
99 * The human language in which the data in the transmission is normally read or
100 * written. It is used primarily by programs to select language-specific
101 * sorting sequences and phonetic name matching algorithms.
102 */
103class LanguageId extends AbstractElement
104{
105    /**
106     * Convert a value to a canonical form.
107     *
108     * @param string $value
109     *
110     * @return string
111     */
112    public function canonical(string $value): string
113    {
114        return preg_replace_callback('/[A-Za-z]+/', static function (array $match): string {
115            return ucwords($match[0]);
116        }, strtolower(parent::canonical($value)));
117    }
118
119
120    /**
121     * A list of controlled values for this element
122     *
123     * @return array<int|string,string>
124     */
125    public function values(): array
126    {
127        $values = [
128            ''              => '',
129            'Afrikaans'     => (new LocaleAf())->endonym(),
130            'Albanian'      => (new LocaleSq())->endonym(),
131            'Amharic'       => (new LocaleAm())->endonym(),
132            'Anglo-Saxon'   => (new LocaleAng())->endonym(),
133            'Arabic'        => (new LocaleAr())->endonym(),
134            'Armenian'      => (new LocaleHy())->endonym(),
135            'Assamese'      => (new LocaleAs())->endonym(),
136            'Belorusian'    => (new LocaleBe())->endonym(),
137            'Bengali'       => (new LocaleBn())->endonym(),
138            //'Braj' => (new LocaleBra())->endonym(),
139            'Bulgarian'     => (new LocaleBg())->endonym(),
140            'Burmese'       => (new LocaleMy())->endonym(),
141            'Cantonese'     => (new LocaleYue())->endonym(),
142            'Catalan'       => (new LocaleCaEsValencia())->endonym(),
143            'Catalan_Spn'   => (new LocaleCa())->endonym(),
144            'Church-Slavic' => (new LocaleCu())->endonym(),
145            'Czech'         => (new LocaleCs())->endonym(),
146            'Danish'        => (new LocaleDa())->endonym(),
147            //'Dogri' => (new LocaleDoi())->endonym(),
148            'Dutch'         => (new LocaleNl())->endonym(),
149            'English'       => (new LocaleEn())->endonym(),
150            'Esperanto'     => (new LocaleEo())->endonym(),
151            'Estonian'      => (new LocaleEt())->endonym(),
152            'Faroese'       => (new LocaleFo())->endonym(),
153            'Finnish'       => (new LocaleFi())->endonym(),
154            'French'        => (new LocaleFr())->endonym(),
155            'Georgian'      => (new LocaleKa())->endonym(),
156            'German'        => (new LocaleDe())->endonym(),
157            'Greek'         => (new LocaleEl())->endonym(),
158            'Gujarati'      => (new LocaleGu())->endonym(),
159            'Hawaiian'      => (new LocaleHaw())->endonym(),
160            'Hebrew'        => (new LocaleHe())->endonym(),
161            'Hindi'         => (new LocaleHi())->endonym(),
162            'Hungarian'     => (new LocaleHu())->endonym(),
163            'Icelandic'     => (new LocaleIs())->endonym(),
164            'Indonesian'    => (new LocaleId())->endonym(),
165            'Italian'       => (new LocaleIt())->endonym(),
166            'Japanese'      => (new LocaleJa())->endonym(),
167            'Kannada'       => (new LocaleKn())->endonym(),
168            'Khmer'         => (new LocaleKm())->endonym(),
169            'Konkani'       => (new LocaleKok())->endonym(),
170            'Korean'        => (new LocaleKo())->endonym(),
171            //'Lahnda' => (new LocaleLah())->endonym(),
172            'Lao'           => (new LocaleLo())->endonym(),
173            'Latvian'       => (new LocaleLv())->endonym(),
174            'Lithuanian'    => (new LocaleLt())->endonym(),
175            'Macedonian'    => (new LocaleMk())->endonym(),
176            //'Maithili' => (new LocaleMai())->endonym(),
177            'Malayalam'     => (new LocaleMl())->endonym(),
178            //'Mandrin' => (new LocaleCmn())->endonym(),
179            //'Manipuri' => (new LocaleMni())->endonym(),
180            'Marathi'       => (new LocaleMr())->endonym(),
181            //'Mewari' => (new LocaleMtr())->endonym(),
182            //'Navaho' => (new LocaleNv())->endonym(),
183            'Nepali'        => (new LocaleNe())->endonym(),
184            'Norwegian'     => (new LocaleNn())->endonym(),
185            'Oriya'         => (new LocaleOr())->endonym(),
186            //'Pahari' => (new LocalePhr())->endonym(),
187            //'Pali' => (new LocalePi())->endonym(),
188            'Panjabi'       => (new LocalePa())->endonym(),
189            'Persian'       => (new LocaleFa())->endonym(),
190            'Polish'        => (new LocalePl())->endonym(),
191            'Portuguese'    => (new LocalePt())->endonym(),
192            //'Prakrit' => (new LocalePra())->endonym(),
193            'Pusto'         => (new LocalePs())->endonym(),
194            //'Rajasthani' => (new LocaleRaj())->endonym(),
195            'Romanian'      => (new LocaleRo())->endonym(),
196            'Russian'       => (new LocaleRu())->endonym(),
197            //'Sanskrit' => (new LocaleSa())->endonym(),
198            'Serb'          => (new LocaleSr())->endonym(),
199            //'Serbo_Croa' => (new LocaleHbs())->endonym(),
200            'Slovak'        => (new LocaleSk())->endonym(),
201            'Slovene'       => (new LocaleSl())->endonym(),
202            'Spanish'       => (new LocaleEs())->endonym(),
203            'Swedish'       => (new LocaleSv())->endonym(),
204            'Tagalog'       => (new LocaleTl())->endonym(),
205            'Tamil'         => (new LocaleTa())->endonym(),
206            'Telugu'        => (new LocaleTe())->endonym(),
207            'Thai'          => (new LocaleTh())->endonym(),
208            'Tibetan'       => (new LocaleBo())->endonym(),
209            'Turkish'       => (new LocaleTr())->endonym(),
210            'Ukrainian'     => (new LocaleUk())->endonym(),
211            'Urdu'          => (new LocaleUr())->endonym(),
212            'Vietnamese'    => (new LocaleVi())->endonym(),
213            //'Wendic' => (new LocaleWen())->endonym(),
214            'Yiddish'       => (new LocaleYi())->endonym(),
215        ];
216
217        uasort($values, I18N::comparator());
218
219        return $values;
220    }
221}
222