1323788f4SGreg Roach<?php 23976b470SGreg Roach 3323788f4SGreg Roach/** 4323788f4SGreg Roach * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 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 * Children take their father’s surname. Wives take their husband’s surname. Surnames are inflected to indicate an individual’s sex. 28323788f4SGreg Roach */ 295206405dSRico Sonntagclass PolishSurnameTradition extends PaternalSurnameTradition 30c1010edaSGreg Roach{ 31e364afe4SGreg Roach // Inflect a surname for females 32e364afe4SGreg Roach private const INFLECT_FEMALE = [ 33323788f4SGreg Roach 'cki\b' => 'cka', 34323788f4SGreg Roach 'dzki\b' => 'dzka', 35323788f4SGreg Roach 'ski\b' => 'ska', 3604a105eeSGreg Roach 'żki\b' => 'żka', 3713abd6f3SGreg Roach ]; 38323788f4SGreg Roach 39e364afe4SGreg Roach // Inflect a surname for males 40e364afe4SGreg Roach private const INFLECT_MALE = [ 41323788f4SGreg Roach 'cka\b' => 'cki', 42323788f4SGreg Roach 'dzka\b' => 'dzki', 43323788f4SGreg Roach 'ska\b' => 'ski', 4404a105eeSGreg Roach 'żka\b' => 'żki', 4513abd6f3SGreg Roach ]; 46323788f4SGreg Roach 47323788f4SGreg Roach /** 487e128bbfSGreg Roach * The name of this surname tradition 497e128bbfSGreg Roach * 507e128bbfSGreg Roach * @return string 517e128bbfSGreg Roach */ 527e128bbfSGreg Roach public function name(): string 537e128bbfSGreg Roach { 547e128bbfSGreg Roach return I18N::translateContext('Surname tradition', 'Polish'); 557e128bbfSGreg Roach } 567e128bbfSGreg Roach 577e128bbfSGreg Roach /** 587e128bbfSGreg Roach * A short description of this surname tradition 597e128bbfSGreg Roach * 607e128bbfSGreg Roach * @return string 617e128bbfSGreg Roach */ 627e128bbfSGreg Roach public function description(): string 637e128bbfSGreg Roach { 647e128bbfSGreg Roach /* I18N: In the Polish surname tradition, ... */ 657e128bbfSGreg Roach return 667e128bbfSGreg Roach I18N::translate('Children take their father’s surname.') . ' ' . 677e128bbfSGreg Roach I18N::translate('Wives take their husband’s surname.') . ' ' . 687e128bbfSGreg Roach I18N::translate('Surnames are inflected to indicate an individual’s gender.'); 697e128bbfSGreg Roach } 707e128bbfSGreg Roach 717e128bbfSGreg Roach /** 72cb7a42eaSGreg Roach * What name is given to a new child 73323788f4SGreg Roach * 74cb7a42eaSGreg Roach * @param Individual|null $father 75cb7a42eaSGreg Roach * @param Individual|null $mother 76cb7a42eaSGreg Roach * @param string $sex 77323788f4SGreg Roach * 7801ffdfd0SGreg Roach * @return array<int,string> 79323788f4SGreg Roach */ 80*1ff45046SGreg Roach public function newChildNames(Individual|null $father, Individual|null $mother, string $sex): array 81c1010edaSGreg Roach { 82ef475b14SGreg Roach if (preg_match(self::REGEX_SURN, $this->extractName($father), $match) === 1) { 83cb7a42eaSGreg Roach if ($sex === 'F') { 84cb7a42eaSGreg Roach $name = $this->inflect($match['NAME'], self::INFLECT_FEMALE); 85cb7a42eaSGreg Roach } else { 86cb7a42eaSGreg Roach $name = $this->inflect($match['NAME'], self::INFLECT_MALE); 87b2ce94c6SRico Sonntag } 88b2ce94c6SRico Sonntag 89cb7a42eaSGreg Roach $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); 90cb7a42eaSGreg Roach 9188a03560SGreg Roach return [$this->buildName($name, ['TYPE' => NameType::VALUE_BIRTH, 'SURN' => $surn])]; 92323788f4SGreg Roach } 93b2ce94c6SRico Sonntag 9488a03560SGreg Roach return [$this->buildName('//', ['TYPE' => NameType::VALUE_BIRTH])]; 95323788f4SGreg Roach } 96323788f4SGreg Roach 97323788f4SGreg Roach /** 98cb7a42eaSGreg Roach * What name is given to a new parent 99323788f4SGreg Roach * 100cb7a42eaSGreg Roach * @param Individual $child 101cb7a42eaSGreg Roach * @param string $sex 102323788f4SGreg Roach * 10301ffdfd0SGreg Roach * @return array<int,string> 104323788f4SGreg Roach */ 105cb7a42eaSGreg Roach public function newParentNames(Individual $child, string $sex): array 106c1010edaSGreg Roach { 107ef475b14SGreg Roach if ($sex === 'M' && preg_match(self::REGEX_SURN, $this->extractName($child), $match) === 1) { 108cb7a42eaSGreg Roach $name = $this->inflect($match['NAME'], self::INFLECT_MALE); 109cb7a42eaSGreg Roach $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); 110b2ce94c6SRico Sonntag 11113abd6f3SGreg Roach return [ 11288a03560SGreg Roach $this->buildName($name, ['TYPE' => NameType::VALUE_BIRTH, 'SURN' => $surn]), 11313abd6f3SGreg Roach ]; 114323788f4SGreg Roach } 115323788f4SGreg Roach 11688a03560SGreg Roach return [$this->buildName('//', ['TYPE' => NameType::VALUE_BIRTH])]; 117cb7a42eaSGreg Roach } 118cb7a42eaSGreg Roach 119323788f4SGreg Roach /** 120323788f4SGreg Roach * What names are given to a new spouse 121323788f4SGreg Roach * 122cb7a42eaSGreg Roach * @param Individual $spouse 123cb7a42eaSGreg Roach * @param string $sex 124323788f4SGreg Roach * 12501ffdfd0SGreg Roach * @return array<int,string> 126323788f4SGreg Roach */ 127cb7a42eaSGreg Roach public function newSpouseNames(Individual $spouse, string $sex): array 128c1010edaSGreg Roach { 129ef475b14SGreg Roach if ($sex === 'F' && preg_match(self::REGEX_SURN, $this->extractName($spouse), $match) === 1) { 130cb7a42eaSGreg Roach $name = $this->inflect($match['NAME'], self::INFLECT_FEMALE); 131cb7a42eaSGreg Roach $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); 132cb7a42eaSGreg Roach 13313abd6f3SGreg Roach return [ 13488a03560SGreg Roach $this->buildName('//', ['TYPE' => NameType::VALUE_BIRTH]), 13588a03560SGreg Roach $this->buildName($name, ['TYPE' => NameType::VALUE_MARRIED, 'SURN' => $surn]), 13613abd6f3SGreg Roach ]; 137b2ce94c6SRico Sonntag } 138b2ce94c6SRico Sonntag 13988a03560SGreg Roach return [$this->buildName('//', ['TYPE' => NameType::VALUE_BIRTH])]; 140323788f4SGreg Roach } 141323788f4SGreg Roach} 142