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