xref: /webtrees/app/SurnameTradition/LithuanianSurnameTradition.php (revision 93a49342332e33b457b78292c20c2dd1fd4d7303)
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\SurnameTradition;
21
22use Fisharebest\Webtrees\Elements\NameType;
23use Fisharebest\Webtrees\Individual;
24
25/**
26 * Lithuanian — Children take their father’s surname. Wives take their husband’s surname. Surnames are inflected to indicate an individual’s sex and marital status.
27 */
28class LithuanianSurnameTradition extends PaternalSurnameTradition
29{
30    // Inflect a surname for wives
31    private const INFLECT_WIFE = [
32        'as\b' => 'ienė',
33        'is\b' => 'ienė',
34        'ys\b' => 'ienė',
35        'us\b' => 'ienė',
36    ];
37
38    // Inflect a surname for daughters
39    private const INFLECT_DAUGHTER = [
40        'a\b'   => 'aitė',
41        'as\b'  => 'aitė',
42        'is\b'  => 'ytė',
43        'ys\b'  => 'ytė',
44        'ius\b' => 'iūtė',
45        'us\b'  => 'utė',
46    ];
47
48    // Inflect a surname for males
49    private const INFLECT_MALE = [
50        'aitė\b' => 'as',
51        'ytė\b'  => 'is',
52        'iūtė\b' => 'ius',
53        'utė\b'  => 'us',
54    ];
55
56    /**
57     * What name is given to a new child
58     *
59     * @param Individual|null $father
60     * @param Individual|null $mother
61     * @param string          $sex
62     *
63     * @return array<int,string>
64     */
65    public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array
66    {
67        if (preg_match(self::REGEX_SURN, $this->extractName($father), $match)) {
68            if ($sex === 'F') {
69                $name = $this->inflect($match['NAME'], self::INFLECT_DAUGHTER);
70                $surn = $this->inflect($match['SURN'], self::INFLECT_MALE);
71            } else {
72                $name = $match['NAME'];
73                $surn = $match['SURN'];
74            }
75
76            return [
77                $this->buildName($name, ['TYPE' => NameType::TYPE_BIRTH, 'SURN' => $surn]),
78            ];
79        }
80
81        return [
82            $this->buildName('//', ['TYPE' => NameType::TYPE_BIRTH]),
83        ];
84    }
85
86    /**
87     * What name is given to a new parent
88     *
89     * @param Individual $child
90     * @param string     $sex
91     *
92     * @return array<int,string>
93     */
94    public function newParentNames(Individual $child, string $sex): array
95    {
96        if ($sex === 'M' && preg_match(self::REGEX_SURN, $this->extractName($child), $match)) {
97            $name = $this->inflect($match['NAME'], self::INFLECT_MALE);
98            $surn = $this->inflect($match['SURN'], self::INFLECT_MALE);
99
100            return [
101                $this->buildName($name, ['TYPE' => NameType::TYPE_BIRTH, 'SURN' => $surn]),
102            ];
103        }
104
105        return [
106            $this->buildName('//', ['TYPE' => NameType::TYPE_BIRTH]),
107        ];
108    }
109
110    /**
111     * What names are given to a new spouse
112     *
113     * @param Individual $spouse
114     * @param string     $sex
115     *
116     * @return array<int,string>
117     */
118    public function newSpouseNames(Individual $spouse, string $sex): array
119    {
120        if ($sex === 'F' && preg_match(self::REGEX_SURN, $this->extractName($spouse), $match)) {
121            $name = $this->inflect($match['NAME'], self::INFLECT_WIFE);
122            $surn = $this->inflect($match['SURN'], self::INFLECT_MALE);
123
124            return [
125                $this->buildName('//', ['TYPE' => NameType::TYPE_BIRTH]),
126                $this->buildName($name, ['TYPE' => NameType::TYPE_MARRIED, 'SURN' => $surn]),
127            ];
128        }
129
130        return [
131            $this->buildName('//', ['TYPE' => NameType::TYPE_BIRTH]),
132        ];
133    }
134}
135