1323788f4SGreg Roach<?php 23976b470SGreg Roach 3323788f4SGreg Roach/** 4323788f4SGreg Roach * webtrees: online genealogy 5*89f7189bSGreg Roach * Copyright (C) 2021 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 15*89f7189bSGreg 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 22323788f4SGreg Roach/** 23323788f4SGreg Roach * Children take their father’s surname. Wives take their husband’s surname. Surnames are inflected to indicate an individual’s sex. 24323788f4SGreg Roach */ 255206405dSRico Sonntagclass PolishSurnameTradition extends PaternalSurnameTradition 26c1010edaSGreg Roach{ 27e364afe4SGreg Roach // Inflect a surname for females 28e364afe4SGreg Roach private const INFLECT_FEMALE = [ 29323788f4SGreg Roach 'cki\b' => 'cka', 30323788f4SGreg Roach 'dzki\b' => 'dzka', 31323788f4SGreg Roach 'ski\b' => 'ska', 3204a105eeSGreg Roach 'żki\b' => 'żka', 3313abd6f3SGreg Roach ]; 34323788f4SGreg Roach 35e364afe4SGreg Roach // Inflect a surname for males 36e364afe4SGreg Roach private const INFLECT_MALE = [ 37323788f4SGreg Roach 'cka\b' => 'cki', 38323788f4SGreg Roach 'dzka\b' => 'dzki', 39323788f4SGreg Roach 'ska\b' => 'ski', 4004a105eeSGreg Roach 'żka\b' => 'żki', 4113abd6f3SGreg Roach ]; 42323788f4SGreg Roach 43323788f4SGreg Roach /** 44323788f4SGreg Roach * What names are given to a new child 45323788f4SGreg Roach * 46323788f4SGreg Roach * @param string $father_name A GEDCOM NAME 47323788f4SGreg Roach * @param string $mother_name A GEDCOM NAME 48323788f4SGreg Roach * @param string $child_sex M, F or U 49323788f4SGreg Roach * 50323788f4SGreg Roach * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 51323788f4SGreg Roach */ 52771ae10aSGreg Roach public function newChildNames(string $father_name, string $mother_name, string $child_sex): array 53c1010edaSGreg Roach { 54323788f4SGreg Roach if (preg_match(self::REGEX_SURN, $father_name, $match)) { 55323788f4SGreg Roach if ($child_sex === 'F') { 5613abd6f3SGreg Roach return array_filter([ 57e364afe4SGreg Roach 'NAME' => $this->inflect($match['NAME'], self::INFLECT_FEMALE), 58e364afe4SGreg Roach 'SURN' => $this->inflect($match['SURN'], self::INFLECT_MALE), 5913abd6f3SGreg Roach ]); 60b2ce94c6SRico Sonntag } 61b2ce94c6SRico Sonntag 6213abd6f3SGreg Roach return array_filter([ 63e364afe4SGreg Roach 'NAME' => $this->inflect($match['NAME'], self::INFLECT_MALE), 64e364afe4SGreg Roach 'SURN' => $this->inflect($match['SURN'], self::INFLECT_MALE), 6513abd6f3SGreg Roach ]); 66323788f4SGreg Roach } 67b2ce94c6SRico Sonntag 6813abd6f3SGreg Roach return [ 69323788f4SGreg Roach 'NAME' => '//', 7013abd6f3SGreg Roach ]; 71323788f4SGreg Roach } 72323788f4SGreg Roach 73323788f4SGreg Roach /** 74323788f4SGreg Roach * What names are given to a new parent 75323788f4SGreg Roach * 76323788f4SGreg Roach * @param string $child_name A GEDCOM NAME 77323788f4SGreg Roach * @param string $parent_sex M, F or U 78323788f4SGreg Roach * 79323788f4SGreg Roach * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 80323788f4SGreg Roach */ 81771ae10aSGreg Roach public function newParentNames(string $child_name, string $parent_sex): array 82c1010edaSGreg Roach { 83323788f4SGreg Roach if ($parent_sex === 'M' && preg_match(self::REGEX_SURN, $child_name, $match)) { 8413abd6f3SGreg Roach return array_filter([ 85e364afe4SGreg Roach 'NAME' => $this->inflect($match['NAME'], self::INFLECT_MALE), 86e364afe4SGreg Roach 'SURN' => $this->inflect($match['SURN'], self::INFLECT_MALE), 8713abd6f3SGreg Roach ]); 88b2ce94c6SRico Sonntag } 89b2ce94c6SRico Sonntag 9013abd6f3SGreg Roach return [ 91323788f4SGreg Roach 'NAME' => '//', 9213abd6f3SGreg Roach ]; 93323788f4SGreg Roach } 94323788f4SGreg Roach 95323788f4SGreg Roach /** 96323788f4SGreg Roach * What names are given to a new spouse 97323788f4SGreg Roach * 98323788f4SGreg Roach * @param string $spouse_name A GEDCOM NAME 99323788f4SGreg Roach * @param string $spouse_sex M, F or U 100323788f4SGreg Roach * 101323788f4SGreg Roach * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 102323788f4SGreg Roach */ 103771ae10aSGreg Roach public function newSpouseNames(string $spouse_name, string $spouse_sex): array 104c1010edaSGreg Roach { 105323788f4SGreg Roach if ($spouse_sex === 'F' && preg_match(self::REGEX_SURN, $spouse_name, $match)) { 10613abd6f3SGreg Roach return [ 107323788f4SGreg Roach 'NAME' => '//', 108e364afe4SGreg Roach '_MARNM' => $this->inflect($match['NAME'], self::INFLECT_FEMALE), 10913abd6f3SGreg Roach ]; 110b2ce94c6SRico Sonntag } 111b2ce94c6SRico Sonntag 11213abd6f3SGreg Roach return [ 113323788f4SGreg Roach 'NAME' => '//', 11413abd6f3SGreg Roach ]; 115323788f4SGreg Roach } 116323788f4SGreg Roach} 117