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