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