xref: /webtrees/app/SurnameTradition/LithuanianSurnameTradition.php (revision c1010eda29c0909ed4d5d463f32d32bfefdd4dfe)
1323788f4SGreg Roach<?php
2323788f4SGreg Roach/**
3323788f4SGreg Roach * webtrees: online genealogy
41062a142SGreg Roach * Copyright (C) 2018 webtrees development team
5323788f4SGreg Roach * This program is free software: you can redistribute it and/or modify
6323788f4SGreg Roach * it under the terms of the GNU General Public License as published by
7323788f4SGreg Roach * the Free Software Foundation, either version 3 of the License, or
8323788f4SGreg Roach * (at your option) any later version.
9323788f4SGreg Roach * This program is distributed in the hope that it will be useful,
10323788f4SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
11323788f4SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12323788f4SGreg Roach * GNU General Public License for more details.
13323788f4SGreg Roach * You should have received a copy of the GNU General Public License
14323788f4SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
15323788f4SGreg Roach */
16323788f4SGreg Roachnamespace Fisharebest\Webtrees\SurnameTradition;
17323788f4SGreg Roach
18323788f4SGreg Roach/**
19323788f4SGreg 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.
20323788f4SGreg Roach */
21*c1010edaSGreg Roachclass LithuanianSurnameTradition extends PaternalSurnameTradition implements SurnameTraditionInterface
22*c1010edaSGreg Roach{
23323788f4SGreg Roach    /** @var string[] Inflect a surname for wives */
2413abd6f3SGreg Roach    protected $inflect_wife = [
25323788f4SGreg Roach        'as\b' => 'ienė',
26323788f4SGreg Roach        'is\b' => 'ienė',
27323788f4SGreg Roach        'ys\b' => 'ienė',
28323788f4SGreg Roach        'us\b' => 'ienė',
2913abd6f3SGreg Roach    ];
30323788f4SGreg Roach
31323788f4SGreg Roach    /** @var string[] Inflect a surname for daughters */
3213abd6f3SGreg Roach    protected $inflect_daughter = [
33323788f4SGreg Roach        'a\b'   => 'aitė',
34323788f4SGreg Roach        'as\b'  => 'aitė',
35323788f4SGreg Roach        'is\b'  => 'ytė',
36323788f4SGreg Roach        'ys\b'  => 'ytė',
37323788f4SGreg Roach        'ius\b' => 'iūtė',
38323788f4SGreg Roach        'us\b'  => 'utė',
3913abd6f3SGreg Roach    ];
40323788f4SGreg Roach
41323788f4SGreg Roach    /** @var string[] Inflect a surname for males */
4213abd6f3SGreg Roach    protected $inflect_male = [
43323788f4SGreg Roach        'aitė\b' => 'as',
44323788f4SGreg Roach        'ytė\b'  => 'is',
45323788f4SGreg Roach        'iūtė\b' => 'ius',
46323788f4SGreg Roach        'utė\b'  => 'us',
4713abd6f3SGreg Roach    ];
48323788f4SGreg Roach
49323788f4SGreg Roach    /**
50323788f4SGreg Roach     * What names are given to a new child
51323788f4SGreg Roach     *
52323788f4SGreg Roach     * @param string $father_name A GEDCOM NAME
53323788f4SGreg Roach     * @param string $mother_name A GEDCOM NAME
54323788f4SGreg Roach     * @param string $child_sex   M, F or U
55323788f4SGreg Roach     *
56323788f4SGreg Roach     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
57323788f4SGreg Roach     */
58*c1010edaSGreg Roach    public function newChildNames($father_name, $mother_name, $child_sex)
59*c1010edaSGreg Roach    {
60323788f4SGreg Roach        if (preg_match(self::REGEX_SURN, $father_name, $match)) {
61323788f4SGreg Roach            if ($child_sex === 'F') {
6213abd6f3SGreg Roach                return array_filter([
63323788f4SGreg Roach                    'NAME' => $this->inflect($match['NAME'], $this->inflect_daughter),
64323788f4SGreg Roach                    'SURN' => $this->inflect($match['SURN'], $this->inflect_male),
6513abd6f3SGreg Roach                ]);
66323788f4SGreg Roach            } else {
6713abd6f3SGreg Roach                return array_filter([
68323788f4SGreg Roach                    'NAME' => $match['NAME'],
69323788f4SGreg Roach                    'SURN' => $match['SURN'],
7013abd6f3SGreg Roach                ]);
71323788f4SGreg Roach            }
72323788f4SGreg Roach        } else {
7313abd6f3SGreg Roach            return [
74323788f4SGreg Roach                'NAME' => '//',
7513abd6f3SGreg Roach            ];
76323788f4SGreg Roach        }
77323788f4SGreg Roach    }
78323788f4SGreg Roach
79323788f4SGreg Roach    /**
80323788f4SGreg Roach     * What names are given to a new parent
81323788f4SGreg Roach     *
82323788f4SGreg Roach     * @param string $child_name A GEDCOM NAME
83323788f4SGreg Roach     * @param string $parent_sex M, F or U
84323788f4SGreg Roach     *
85323788f4SGreg Roach     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
86323788f4SGreg Roach     */
87*c1010edaSGreg Roach    public function newParentNames($child_name, $parent_sex)
88*c1010edaSGreg Roach    {
89323788f4SGreg Roach        if ($parent_sex === 'M' && preg_match(self::REGEX_SURN, $child_name, $match)) {
9013abd6f3SGreg Roach            return array_filter([
91323788f4SGreg Roach                'NAME' => $this->inflect($match['NAME'], $this->inflect_male),
92323788f4SGreg Roach                'SURN' => $this->inflect($match['SURN'], $this->inflect_male),
9313abd6f3SGreg Roach            ]);
94323788f4SGreg Roach        } else {
9513abd6f3SGreg Roach            return [
96323788f4SGreg Roach                'NAME' => '//',
9713abd6f3SGreg Roach            ];
98323788f4SGreg Roach        }
99323788f4SGreg Roach    }
100323788f4SGreg Roach
101323788f4SGreg Roach    /**
102323788f4SGreg Roach     * What names are given to a new spouse
103323788f4SGreg Roach     *
104323788f4SGreg Roach     * @param string $spouse_name A GEDCOM NAME
105323788f4SGreg Roach     * @param string $spouse_sex  M, F or U
106323788f4SGreg Roach     *
107323788f4SGreg Roach     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
108323788f4SGreg Roach     */
109*c1010edaSGreg Roach    public function newSpouseNames($spouse_name, $spouse_sex)
110*c1010edaSGreg Roach    {
111323788f4SGreg Roach        if ($spouse_sex === 'F' && preg_match(self::REGEX_SURN, $spouse_name, $match)) {
11213abd6f3SGreg Roach            return [
113323788f4SGreg Roach                'NAME'   => '//',
114323788f4SGreg Roach                '_MARNM' => $this->inflect($match['NAME'], $this->inflect_wife),
11513abd6f3SGreg Roach            ];
116323788f4SGreg Roach        } else {
11713abd6f3SGreg Roach            return [
118323788f4SGreg Roach                'NAME' => '//',
11913abd6f3SGreg Roach            ];
120323788f4SGreg Roach        }
121323788f4SGreg Roach    }
122323788f4SGreg Roach}
123