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