1323788f4SGreg Roach<?php 23976b470SGreg Roach 3323788f4SGreg Roach/** 4323788f4SGreg Roach * webtrees: online genealogy 55bfc6897SGreg Roach * Copyright (C) 2022 webtrees development team 6323788f4SGreg Roach * This program is free software: you can redistribute it and/or modify 7323788f4SGreg Roach * it under the terms of the GNU General Public License as published by 8323788f4SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9323788f4SGreg Roach * (at your option) any later version. 10323788f4SGreg Roach * This program is distributed in the hope that it will be useful, 11323788f4SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12323788f4SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13323788f4SGreg Roach * GNU General Public License for more details. 14323788f4SGreg Roach * You should have received a copy of the GNU General Public License 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 16323788f4SGreg Roach */ 17fcfa147eSGreg Roach 18e7f56f2aSGreg Roachdeclare(strict_types=1); 19e7f56f2aSGreg Roach 20323788f4SGreg Roachnamespace Fisharebest\Webtrees\SurnameTradition; 21323788f4SGreg Roach 227c29ac65SGreg Roachuse Fisharebest\Webtrees\Elements\NameType; 237e128bbfSGreg Roachuse Fisharebest\Webtrees\I18N; 24cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Individual; 25cb7a42eaSGreg Roach 26323788f4SGreg Roach/** 27323788f4SGreg 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. 28323788f4SGreg Roach */ 295206405dSRico Sonntagclass LithuanianSurnameTradition extends PaternalSurnameTradition 30c1010edaSGreg Roach{ 31e364afe4SGreg Roach // Inflect a surname for wives 32e364afe4SGreg Roach private const INFLECT_WIFE = [ 33323788f4SGreg Roach 'as\b' => 'ienė', 34323788f4SGreg Roach 'is\b' => 'ienė', 35323788f4SGreg Roach 'ys\b' => 'ienė', 36323788f4SGreg Roach 'us\b' => 'ienė', 3713abd6f3SGreg Roach ]; 38323788f4SGreg Roach 39e364afe4SGreg Roach // Inflect a surname for daughters 40e364afe4SGreg Roach private const INFLECT_DAUGHTER = [ 41323788f4SGreg Roach 'a\b' => 'aitė', 42323788f4SGreg Roach 'as\b' => 'aitė', 43323788f4SGreg Roach 'is\b' => 'ytė', 44323788f4SGreg Roach 'ys\b' => 'ytė', 45323788f4SGreg Roach 'ius\b' => 'iūtė', 46323788f4SGreg Roach 'us\b' => 'utė', 4713abd6f3SGreg Roach ]; 48323788f4SGreg Roach 49e364afe4SGreg Roach // Inflect a surname for males 50e364afe4SGreg Roach private const INFLECT_MALE = [ 51323788f4SGreg Roach 'aitė\b' => 'as', 52323788f4SGreg Roach 'ytė\b' => 'is', 53323788f4SGreg Roach 'iūtė\b' => 'ius', 54323788f4SGreg Roach 'utė\b' => 'us', 5513abd6f3SGreg Roach ]; 56323788f4SGreg Roach 57323788f4SGreg Roach /** 587e128bbfSGreg Roach * The name of this surname tradition 597e128bbfSGreg Roach * 607e128bbfSGreg Roach * @return string 617e128bbfSGreg Roach */ 627e128bbfSGreg Roach public function name(): string 637e128bbfSGreg Roach { 647e128bbfSGreg Roach return I18N::translateContext('Surname tradition', 'Lithuanian'); 657e128bbfSGreg Roach } 667e128bbfSGreg Roach 677e128bbfSGreg Roach /** 687e128bbfSGreg Roach * A short description of this surname tradition 697e128bbfSGreg Roach * 707e128bbfSGreg Roach * @return string 717e128bbfSGreg Roach */ 727e128bbfSGreg Roach public function description(): string 737e128bbfSGreg Roach { 747e128bbfSGreg Roach /* I18N: In the Lithuanian surname tradition, ... */ 757e128bbfSGreg Roach return 767e128bbfSGreg Roach I18N::translate('Children take their father’s surname.') . ' ' . 777e128bbfSGreg Roach I18N::translate('Wives take their husband’s surname.') . ' ' . 787e128bbfSGreg Roach I18N::translate('Surnames are inflected to indicate an individual’s gender and marital status.'); 797e128bbfSGreg Roach } 807e128bbfSGreg Roach 817e128bbfSGreg Roach /** 82cb7a42eaSGreg Roach * What name is given to a new child 83323788f4SGreg Roach * 84cb7a42eaSGreg Roach * @param Individual|null $father 85cb7a42eaSGreg Roach * @param Individual|null $mother 86cb7a42eaSGreg Roach * @param string $sex 87323788f4SGreg Roach * 8801ffdfd0SGreg Roach * @return array<int,string> 89323788f4SGreg Roach */ 90cb7a42eaSGreg Roach public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array 91c1010edaSGreg Roach { 92*ef475b14SGreg Roach if (preg_match(self::REGEX_SURN, $this->extractName($father), $match) === 1) { 93cb7a42eaSGreg Roach if ($sex === 'F') { 94cb7a42eaSGreg Roach $name = $this->inflect($match['NAME'], self::INFLECT_DAUGHTER); 95cb7a42eaSGreg Roach $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); 96cb7a42eaSGreg Roach } else { 97cb7a42eaSGreg Roach $name = $match['NAME']; 98cb7a42eaSGreg Roach $surn = $match['SURN']; 99323788f4SGreg Roach } 100b2ce94c6SRico Sonntag 10113abd6f3SGreg Roach return [ 10288a03560SGreg Roach $this->buildName($name, ['TYPE' => NameType::VALUE_BIRTH, 'SURN' => $surn]), 103cb7a42eaSGreg Roach ]; 104cb7a42eaSGreg Roach } 105cb7a42eaSGreg Roach 106cb7a42eaSGreg Roach return [ 10788a03560SGreg Roach $this->buildName('//', ['TYPE' => NameType::VALUE_BIRTH]), 10813abd6f3SGreg Roach ]; 109323788f4SGreg Roach } 110323788f4SGreg Roach 111323788f4SGreg Roach /** 112cb7a42eaSGreg Roach * What name is given to a new parent 113323788f4SGreg Roach * 114cb7a42eaSGreg Roach * @param Individual $child 115cb7a42eaSGreg Roach * @param string $sex 116323788f4SGreg Roach * 11701ffdfd0SGreg Roach * @return array<int,string> 118323788f4SGreg Roach */ 119cb7a42eaSGreg Roach public function newParentNames(Individual $child, string $sex): array 120c1010edaSGreg Roach { 121*ef475b14SGreg Roach if ($sex === 'M' && preg_match(self::REGEX_SURN, $this->extractName($child), $match) === 1) { 122cb7a42eaSGreg Roach $name = $this->inflect($match['NAME'], self::INFLECT_MALE); 123cb7a42eaSGreg Roach $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); 124cb7a42eaSGreg Roach 125cb7a42eaSGreg Roach return [ 12688a03560SGreg Roach $this->buildName($name, ['TYPE' => NameType::VALUE_BIRTH, 'SURN' => $surn]), 127cb7a42eaSGreg Roach ]; 128b2ce94c6SRico Sonntag } 129b2ce94c6SRico Sonntag 13013abd6f3SGreg Roach return [ 13188a03560SGreg Roach $this->buildName('//', ['TYPE' => NameType::VALUE_BIRTH]), 13213abd6f3SGreg Roach ]; 133323788f4SGreg Roach } 134323788f4SGreg Roach 135323788f4SGreg Roach /** 136323788f4SGreg Roach * What names are given to a new spouse 137323788f4SGreg Roach * 138cb7a42eaSGreg Roach * @param Individual $spouse 139cb7a42eaSGreg Roach * @param string $sex 140323788f4SGreg Roach * 14101ffdfd0SGreg Roach * @return array<int,string> 142323788f4SGreg Roach */ 143cb7a42eaSGreg Roach public function newSpouseNames(Individual $spouse, string $sex): array 144c1010edaSGreg Roach { 145*ef475b14SGreg Roach if ($sex === 'F' && preg_match(self::REGEX_SURN, $this->extractName($spouse), $match) === 1) { 146cb7a42eaSGreg Roach $name = $this->inflect($match['NAME'], self::INFLECT_WIFE); 147cb7a42eaSGreg Roach $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); 148cb7a42eaSGreg Roach 14913abd6f3SGreg Roach return [ 15088a03560SGreg Roach $this->buildName('//', ['TYPE' => NameType::VALUE_BIRTH]), 15188a03560SGreg Roach $this->buildName($name, ['TYPE' => NameType::VALUE_MARRIED, 'SURN' => $surn]), 15213abd6f3SGreg Roach ]; 153b2ce94c6SRico Sonntag } 154b2ce94c6SRico Sonntag 15513abd6f3SGreg Roach return [ 15688a03560SGreg Roach $this->buildName('//', ['TYPE' => NameType::VALUE_BIRTH]), 15713abd6f3SGreg Roach ]; 158323788f4SGreg Roach } 159323788f4SGreg Roach} 160