1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2023 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\Elements\NameType; 23use Fisharebest\Webtrees\I18N; 24use Fisharebest\Webtrees\Individual; 25 26/** 27 * Children take their father’s surname. Wives take their husband’s surname. Surnames are inflected to indicate an individual’s sex. 28 */ 29class PolishSurnameTradition extends PaternalSurnameTradition 30{ 31 // Inflect a surname for females 32 private const INFLECT_FEMALE = [ 33 'cki\b' => 'cka', 34 'dzki\b' => 'dzka', 35 'ski\b' => 'ska', 36 'żki\b' => 'żka', 37 ]; 38 39 // Inflect a surname for males 40 private const INFLECT_MALE = [ 41 'cka\b' => 'cki', 42 'dzka\b' => 'dzki', 43 'ska\b' => 'ski', 44 'żka\b' => 'żki', 45 ]; 46 47 /** 48 * The name of this surname tradition 49 * 50 * @return string 51 */ 52 public function name(): string 53 { 54 return I18N::translateContext('Surname tradition', 'Polish'); 55 } 56 57 /** 58 * A short description of this surname tradition 59 * 60 * @return string 61 */ 62 public function description(): string 63 { 64 /* I18N: In the Polish surname tradition, ... */ 65 return 66 I18N::translate('Children take their father’s surname.') . ' ' . 67 I18N::translate('Wives take their husband’s surname.') . ' ' . 68 I18N::translate('Surnames are inflected to indicate an individual’s gender.'); 69 } 70 71 /** 72 * What name is given to a new child 73 * 74 * @param Individual|null $father 75 * @param Individual|null $mother 76 * @param string $sex 77 * 78 * @return array<int,string> 79 */ 80 public function newChildNames(Individual|null $father, Individual|null $mother, string $sex): array 81 { 82 if (preg_match(self::REGEX_SURN, $this->extractName($father), $match) === 1) { 83 if ($sex === 'F') { 84 $name = $this->inflect($match['NAME'], self::INFLECT_FEMALE); 85 } else { 86 $name = $this->inflect($match['NAME'], self::INFLECT_MALE); 87 } 88 89 $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); 90 91 return [$this->buildName($name, ['TYPE' => NameType::VALUE_BIRTH, 'SURN' => $surn])]; 92 } 93 94 return [$this->buildName('//', ['TYPE' => NameType::VALUE_BIRTH])]; 95 } 96 97 /** 98 * What name is given to a new parent 99 * 100 * @param Individual $child 101 * @param string $sex 102 * 103 * @return array<int,string> 104 */ 105 public function newParentNames(Individual $child, string $sex): array 106 { 107 if ($sex === 'M' && preg_match(self::REGEX_SURN, $this->extractName($child), $match) === 1) { 108 $name = $this->inflect($match['NAME'], self::INFLECT_MALE); 109 $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); 110 111 return [ 112 $this->buildName($name, ['TYPE' => NameType::VALUE_BIRTH, 'SURN' => $surn]), 113 ]; 114 } 115 116 return [$this->buildName('//', ['TYPE' => NameType::VALUE_BIRTH])]; 117 } 118 119 /** 120 * What names are given to a new spouse 121 * 122 * @param Individual $spouse 123 * @param string $sex 124 * 125 * @return array<int,string> 126 */ 127 public function newSpouseNames(Individual $spouse, string $sex): array 128 { 129 if ($sex === 'F' && preg_match(self::REGEX_SURN, $this->extractName($spouse), $match) === 1) { 130 $name = $this->inflect($match['NAME'], self::INFLECT_FEMALE); 131 $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); 132 133 return [ 134 $this->buildName('//', ['TYPE' => NameType::VALUE_BIRTH]), 135 $this->buildName($name, ['TYPE' => NameType::VALUE_MARRIED, 'SURN' => $surn]), 136 ]; 137 } 138 139 return [$this->buildName('//', ['TYPE' => NameType::VALUE_BIRTH])]; 140 } 141} 142