xref: /webtrees/app/SurnameTradition/LithuanianSurnameTradition.php (revision 83615acfc72bfb50678c6481f2a00bab04041a87)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
16 */
17declare(strict_types=1);
18
19namespace Fisharebest\Webtrees\SurnameTradition;
20
21/**
22 * 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.
23 */
24class LithuanianSurnameTradition extends PaternalSurnameTradition
25{
26    // Inflect a surname for wives
27    private const INFLECT_WIFE = [
28        'as\b' => 'ienė',
29        'is\b' => 'ienė',
30        'ys\b' => 'ienė',
31        'us\b' => 'ienė',
32    ];
33
34    // Inflect a surname for daughters
35    private const INFLECT_DAUGHTER = [
36        'a\b'   => 'aitė',
37        'as\b'  => 'aitė',
38        'is\b'  => 'ytė',
39        'ys\b'  => 'ytė',
40        'ius\b' => 'iūtė',
41        'us\b'  => 'utė',
42    ];
43
44    // Inflect a surname for males
45    private const INFLECT_MALE = [
46        'aitė\b' => 'as',
47        'ytė\b'  => 'is',
48        'iūtė\b' => 'ius',
49        'utė\b'  => 'us',
50    ];
51
52    /**
53     * What names are given to a new child
54     *
55     * @param string $father_name A GEDCOM NAME
56     * @param string $mother_name A GEDCOM NAME
57     * @param string $child_sex   M, F or U
58     *
59     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
60     */
61    public function newChildNames(string $father_name, string $mother_name, string $child_sex): array
62    {
63        if (preg_match(self::REGEX_SURN, $father_name, $match)) {
64            if ($child_sex === 'F') {
65                return array_filter([
66                    'NAME' => $this->inflect($match['NAME'], self::INFLECT_DAUGHTER),
67                    'SURN' => $this->inflect($match['SURN'], self::INFLECT_MALE),
68                ]);
69            }
70
71            return array_filter([
72                'NAME' => $match['NAME'],
73                'SURN' => $match['SURN'],
74            ]);
75        }
76
77        return [
78            'NAME' => '//',
79        ];
80    }
81
82    /**
83     * What names are given to a new parent
84     *
85     * @param string $child_name A GEDCOM NAME
86     * @param string $parent_sex M, F or U
87     *
88     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
89     */
90    public function newParentNames(string $child_name, string $parent_sex): array
91    {
92        if ($parent_sex === 'M' && preg_match(self::REGEX_SURN, $child_name, $match)) {
93            return array_filter([
94                'NAME' => $this->inflect($match['NAME'], self::INFLECT_MALE),
95                'SURN' => $this->inflect($match['SURN'], self::INFLECT_MALE),
96            ]);
97        }
98
99        return [
100            'NAME' => '//',
101        ];
102    }
103
104    /**
105     * What names are given to a new spouse
106     *
107     * @param string $spouse_name A GEDCOM NAME
108     * @param string $spouse_sex  M, F or U
109     *
110     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
111     */
112    public function newSpouseNames(string $spouse_name, string $spouse_sex): array
113    {
114        if ($spouse_sex === 'F' && preg_match(self::REGEX_SURN, $spouse_name, $match)) {
115            return [
116                'NAME'   => '//',
117                '_MARNM' => $this->inflect($match['NAME'], self::INFLECT_WIFE),
118            ];
119        }
120
121        return [
122            'NAME' => '//',
123        ];
124    }
125}
126