xref: /webtrees/app/SurnameTradition/LithuanianSurnameTradition.php (revision 4e73f0bda96a34c06bd4b8e67501ef4955895fbf)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2019 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees\SurnameTradition;
19
20/**
21 * 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.
22 */
23class LithuanianSurnameTradition extends PaternalSurnameTradition
24{
25    /** @var string[] Inflect a surname for wives */
26    protected $inflect_wife = [
27        'as\b' => 'ienė',
28        'is\b' => 'ienė',
29        'ys\b' => 'ienė',
30        'us\b' => 'ienė',
31    ];
32
33    /** @var string[] Inflect a surname for daughters */
34    protected $inflect_daughter = [
35        'a\b'   => 'aitė',
36        'as\b'  => 'aitė',
37        'is\b'  => 'ytė',
38        'ys\b'  => 'ytė',
39        'ius\b' => 'iūtė',
40        'us\b'  => 'utė',
41    ];
42
43    /** @var string[] Inflect a surname for males */
44    protected $inflect_male = [
45        'aitė\b' => 'as',
46        'ytė\b'  => 'is',
47        'iūtė\b' => 'ius',
48        'utė\b'  => 'us',
49    ];
50
51    /**
52     * What names are given to a new child
53     *
54     * @param string $father_name A GEDCOM NAME
55     * @param string $mother_name A GEDCOM NAME
56     * @param string $child_sex   M, F or U
57     *
58     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
59     */
60    public function newChildNames(string $father_name, string $mother_name, string $child_sex): array
61    {
62        if (preg_match(self::REGEX_SURN, $father_name, $match)) {
63            if ($child_sex === 'F') {
64                return array_filter([
65                    'NAME' => $this->inflect($match['NAME'], $this->inflect_daughter),
66                    'SURN' => $this->inflect($match['SURN'], $this->inflect_male),
67                ]);
68            }
69
70            return array_filter([
71                'NAME' => $match['NAME'],
72                'SURN' => $match['SURN'],
73            ]);
74        }
75
76        return [
77            'NAME' => '//',
78        ];
79    }
80
81    /**
82     * What names are given to a new parent
83     *
84     * @param string $child_name A GEDCOM NAME
85     * @param string $parent_sex M, F or U
86     *
87     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
88     */
89    public function newParentNames(string $child_name, string $parent_sex): array
90    {
91        if ($parent_sex === 'M' && preg_match(self::REGEX_SURN, $child_name, $match)) {
92            return array_filter([
93                'NAME' => $this->inflect($match['NAME'], $this->inflect_male),
94                'SURN' => $this->inflect($match['SURN'], $this->inflect_male),
95            ]);
96        }
97
98        return [
99            'NAME' => '//',
100        ];
101    }
102
103    /**
104     * What names are given to a new spouse
105     *
106     * @param string $spouse_name A GEDCOM NAME
107     * @param string $spouse_sex  M, F or U
108     *
109     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
110     */
111    public function newSpouseNames(string $spouse_name, string $spouse_sex): array
112    {
113        if ($spouse_sex === 'F' && preg_match(self::REGEX_SURN, $spouse_name, $match)) {
114            return [
115                'NAME'   => '//',
116                '_MARNM' => $this->inflect($match['NAME'], $this->inflect_wife),
117            ];
118        }
119
120        return [
121            'NAME' => '//',
122        ];
123    }
124}
125