xref: /webtrees/app/SurnameTradition/LithuanianSurnameTradition.php (revision 5bfc689774bb9a6401271c4ed15a6d50652c991b)
1323788f4SGreg Roach<?php
23976b470SGreg Roach
3323788f4SGreg Roach/**
4323788f4SGreg Roach * webtrees: online genealogy
5*5bfc6897SGreg Roach * Copyright (C) 2022 webtrees development team
6323788f4SGreg Roach * This program is free software: you can redistribute it and/or modify
7323788f4SGreg Roach * it under the terms of the GNU General Public License as published by
8323788f4SGreg Roach * the Free Software Foundation, either version 3 of the License, or
9323788f4SGreg Roach * (at your option) any later version.
10323788f4SGreg Roach * This program is distributed in the hope that it will be useful,
11323788f4SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12323788f4SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13323788f4SGreg Roach * GNU General Public License for more details.
14323788f4SGreg 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/>.
16323788f4SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
20323788f4SGreg Roachnamespace Fisharebest\Webtrees\SurnameTradition;
21323788f4SGreg Roach
22cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Individual;
23cb7a42eaSGreg Roach
24323788f4SGreg Roach/**
25323788f4SGreg Roach * 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.
26323788f4SGreg Roach */
275206405dSRico Sonntagclass LithuanianSurnameTradition extends PaternalSurnameTradition
28c1010edaSGreg Roach{
29e364afe4SGreg Roach    // Inflect a surname for wives
30e364afe4SGreg Roach    private const INFLECT_WIFE = [
31323788f4SGreg Roach        'as\b' => 'ienė',
32323788f4SGreg Roach        'is\b' => 'ienė',
33323788f4SGreg Roach        'ys\b' => 'ienė',
34323788f4SGreg Roach        'us\b' => 'ienė',
3513abd6f3SGreg Roach    ];
36323788f4SGreg Roach
37e364afe4SGreg Roach    // Inflect a surname for daughters
38e364afe4SGreg Roach    private const INFLECT_DAUGHTER = [
39323788f4SGreg Roach        'a\b'   => 'aitė',
40323788f4SGreg Roach        'as\b'  => 'aitė',
41323788f4SGreg Roach        'is\b'  => 'ytė',
42323788f4SGreg Roach        'ys\b'  => 'ytė',
43323788f4SGreg Roach        'ius\b' => 'iūtė',
44323788f4SGreg Roach        'us\b'  => 'utė',
4513abd6f3SGreg Roach    ];
46323788f4SGreg Roach
47e364afe4SGreg Roach    // Inflect a surname for males
48e364afe4SGreg Roach    private const INFLECT_MALE = [
49323788f4SGreg Roach        'aitė\b' => 'as',
50323788f4SGreg Roach        'ytė\b'  => 'is',
51323788f4SGreg Roach        'iūtė\b' => 'ius',
52323788f4SGreg Roach        'utė\b'  => 'us',
5313abd6f3SGreg Roach    ];
54323788f4SGreg Roach
55323788f4SGreg Roach    /**
56cb7a42eaSGreg Roach     * What name is given to a new child
57323788f4SGreg Roach     *
58cb7a42eaSGreg Roach     * @param Individual|null $father
59cb7a42eaSGreg Roach     * @param Individual|null $mother
60cb7a42eaSGreg Roach     * @param string          $sex
61323788f4SGreg Roach     *
6201ffdfd0SGreg Roach     * @return array<int,string>
63323788f4SGreg Roach     */
64cb7a42eaSGreg Roach    public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array
65c1010edaSGreg Roach    {
66cb7a42eaSGreg Roach        if (preg_match(self::REGEX_SURN, $this->extractName($father), $match)) {
67cb7a42eaSGreg Roach            if ($sex === 'F') {
68cb7a42eaSGreg Roach                $name = $this->inflect($match['NAME'], self::INFLECT_DAUGHTER);
69cb7a42eaSGreg Roach                $surn = $this->inflect($match['SURN'], self::INFLECT_MALE);
70cb7a42eaSGreg Roach            } else {
71cb7a42eaSGreg Roach                $name = $match['NAME'];
72cb7a42eaSGreg Roach                $surn = $match['SURN'];
73323788f4SGreg Roach            }
74b2ce94c6SRico Sonntag
7513abd6f3SGreg Roach            return [
76cb7a42eaSGreg Roach                $this->buildName($name, ['TYPE' => 'birth', 'SURN' => $surn]),
77cb7a42eaSGreg Roach            ];
78cb7a42eaSGreg Roach        }
79cb7a42eaSGreg Roach
80cb7a42eaSGreg Roach        return [
81cb7a42eaSGreg Roach            $this->buildName('//', ['TYPE' => 'birth']),
8213abd6f3SGreg Roach        ];
83323788f4SGreg Roach    }
84323788f4SGreg Roach
85323788f4SGreg Roach    /**
86cb7a42eaSGreg Roach     * What name is given to a new parent
87323788f4SGreg Roach     *
88cb7a42eaSGreg Roach     * @param Individual $child
89cb7a42eaSGreg Roach     * @param string     $sex
90323788f4SGreg Roach     *
9101ffdfd0SGreg Roach     * @return array<int,string>
92323788f4SGreg Roach     */
93cb7a42eaSGreg Roach    public function newParentNames(Individual $child, string $sex): array
94c1010edaSGreg Roach    {
95cb7a42eaSGreg Roach        if ($sex === 'M' && preg_match(self::REGEX_SURN, $this->extractName($child), $match)) {
96cb7a42eaSGreg Roach            $name = $this->inflect($match['NAME'], self::INFLECT_MALE);
97cb7a42eaSGreg Roach            $surn = $this->inflect($match['SURN'], self::INFLECT_MALE);
98cb7a42eaSGreg Roach
99cb7a42eaSGreg Roach            return [
100cb7a42eaSGreg Roach                $this->buildName($name, ['TYPE' => 'birth', 'SURN' => $surn]),
101cb7a42eaSGreg Roach            ];
102b2ce94c6SRico Sonntag        }
103b2ce94c6SRico Sonntag
10413abd6f3SGreg Roach        return [
105cb7a42eaSGreg Roach            $this->buildName('//', ['TYPE' => 'birth']),
10613abd6f3SGreg Roach        ];
107323788f4SGreg Roach    }
108323788f4SGreg Roach
109323788f4SGreg Roach    /**
110323788f4SGreg Roach     * What names are given to a new spouse
111323788f4SGreg Roach     *
112cb7a42eaSGreg Roach     * @param Individual $spouse
113cb7a42eaSGreg Roach     * @param string     $sex
114323788f4SGreg Roach     *
11501ffdfd0SGreg Roach     * @return array<int,string>
116323788f4SGreg Roach     */
117cb7a42eaSGreg Roach    public function newSpouseNames(Individual $spouse, string $sex): array
118c1010edaSGreg Roach    {
119cb7a42eaSGreg Roach        if ($sex === 'F' && preg_match(self::REGEX_SURN, $this->extractName($spouse), $match)) {
120cb7a42eaSGreg Roach            $name = $this->inflect($match['NAME'], self::INFLECT_WIFE);
121cb7a42eaSGreg Roach            $surn = $this->inflect($match['SURN'], self::INFLECT_MALE);
122cb7a42eaSGreg Roach
12313abd6f3SGreg Roach            return [
124cb7a42eaSGreg Roach                $this->buildName('//', ['TYPE' => 'birth']),
125cb7a42eaSGreg Roach                $this->buildName($name, ['TYPE' => 'married', 'SURN' => $surn]),
12613abd6f3SGreg Roach            ];
127b2ce94c6SRico Sonntag        }
128b2ce94c6SRico Sonntag
12913abd6f3SGreg Roach        return [
130cb7a42eaSGreg Roach            $this->buildName('//', ['TYPE' => 'birth']),
13113abd6f3SGreg Roach        ];
132323788f4SGreg Roach    }
133323788f4SGreg Roach}
134