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 * Children take a patronym instead of a surname. 28323788f4SGreg Roach * 29323788f4SGreg Roach * Sons get their father’s given name plus “sson” 30323788f4SGreg Roach * Daughters get their father’s given name plus “sdottir” 31323788f4SGreg Roach */ 325206405dSRico Sonntagclass IcelandicSurnameTradition extends DefaultSurnameTradition 33c1010edaSGreg Roach{ 34323788f4SGreg Roach /** 357e128bbfSGreg Roach * The name of this surname tradition 367e128bbfSGreg Roach * 377e128bbfSGreg Roach * @return string 387e128bbfSGreg Roach */ 397e128bbfSGreg Roach public function name(): string 407e128bbfSGreg Roach { 417e128bbfSGreg Roach return I18N::translateContext('Surname tradition', 'Icelandic'); 427e128bbfSGreg Roach } 437e128bbfSGreg Roach 447e128bbfSGreg Roach /** 457e128bbfSGreg Roach * A short description of this surname tradition 467e128bbfSGreg Roach * 477e128bbfSGreg Roach * @return string 487e128bbfSGreg Roach */ 497e128bbfSGreg Roach public function description(): string 507e128bbfSGreg Roach { 517e128bbfSGreg Roach /* I18N: In the Icelandic surname tradition, ... */ 527e128bbfSGreg Roach return I18N::translate('Children take a patronym instead of a surname.'); 537e128bbfSGreg Roach } 547e128bbfSGreg Roach 557e128bbfSGreg Roach /** 56a171b6a5SGreg Roach * A default/empty name 57c1ec7145SGreg Roach * 58a171b6a5SGreg Roach * @return string 59c1ec7145SGreg Roach */ 60a171b6a5SGreg Roach public function defaultName(): string 61c1010edaSGreg Roach { 62a171b6a5SGreg Roach return ''; 63c1ec7145SGreg Roach } 64c1ec7145SGreg Roach 65c1ec7145SGreg Roach /** 66cb7a42eaSGreg Roach * What name is given to a new child 67323788f4SGreg Roach * 68cb7a42eaSGreg Roach * @param Individual|null $father 69cb7a42eaSGreg Roach * @param Individual|null $mother 70cb7a42eaSGreg Roach * @param string $sex 71323788f4SGreg Roach * 7201ffdfd0SGreg Roach * @return array<int,string> 73323788f4SGreg Roach */ 74cb7a42eaSGreg Roach public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array 75c1010edaSGreg Roach { 76*ef475b14SGreg Roach if (preg_match(self::REGEX_GIVN, $this->extractName($father), $match) === 1) { 77cb7a42eaSGreg Roach switch ($sex) { 78323788f4SGreg Roach case 'M': 79cb7a42eaSGreg Roach $givn = $match['GIVN'] . 'sson'; 80cb7a42eaSGreg Roach 8113abd6f3SGreg Roach return [ 8288a03560SGreg Roach $this->buildName($givn, ['TYPE' => NameType::VALUE_BIRTH, 'GIVN' => $givn]), 8313abd6f3SGreg Roach ]; 84cb7a42eaSGreg Roach 85323788f4SGreg Roach case 'F': 86cb7a42eaSGreg Roach $givn = $match['GIVN'] . 'sdottir'; 87cb7a42eaSGreg Roach 8813abd6f3SGreg Roach return [ 8988a03560SGreg Roach $this->buildName($givn, ['TYPE' => NameType::VALUE_BIRTH, 'GIVN' => $givn]), 9013abd6f3SGreg Roach ]; 91323788f4SGreg Roach } 92323788f4SGreg Roach } 93323788f4SGreg Roach 94cb7a42eaSGreg Roach return [ 9588a03560SGreg Roach $this->buildName('', ['TYPE' => NameType::VALUE_BIRTH]), 96cb7a42eaSGreg Roach ]; 97323788f4SGreg Roach } 98323788f4SGreg Roach 99323788f4SGreg Roach /** 100cb7a42eaSGreg Roach * What name is given to a new parent 101323788f4SGreg Roach * 102cb7a42eaSGreg Roach * @param Individual $child 103cb7a42eaSGreg Roach * @param string $sex 104323788f4SGreg Roach * 10501ffdfd0SGreg Roach * @return array<int,string> 106323788f4SGreg Roach */ 107cb7a42eaSGreg Roach public function newParentNames(Individual $child, string $sex): array 108c1010edaSGreg Roach { 109*ef475b14SGreg Roach if ($sex === 'M' && preg_match('~(?<GIVN>[^ /]+)(:?sson)$~', $this->extractName($child), $match) === 1) { 11013abd6f3SGreg Roach return [ 11188a03560SGreg Roach $this->buildName($match['GIVN'], ['TYPE' => NameType::VALUE_BIRTH, 'GIVN' => $match['GIVN']]), 11213abd6f3SGreg Roach ]; 113323788f4SGreg Roach } 114b2ce94c6SRico Sonntag 115*ef475b14SGreg Roach if ($sex === 'F' && preg_match('~(?<GIVN>[^ /]+)(:?sdottir)$~', $this->extractName($child), $match) === 1) { 116cb7a42eaSGreg Roach return [ 11788a03560SGreg Roach $this->buildName($match['GIVN'], ['TYPE' => NameType::VALUE_BIRTH, 'GIVN' => $match['GIVN']]), 118cb7a42eaSGreg Roach ]; 119cb7a42eaSGreg Roach } 120cb7a42eaSGreg Roach 121cb7a42eaSGreg Roach return [ 12288a03560SGreg Roach $this->buildName('', ['TYPE' => NameType::VALUE_BIRTH]), 123cb7a42eaSGreg Roach ]; 124323788f4SGreg Roach } 125323788f4SGreg Roach 126323788f4SGreg Roach /** 127323788f4SGreg Roach * What names are given to a new spouse 128323788f4SGreg Roach * 129cb7a42eaSGreg Roach * @param Individual $spouse 130cb7a42eaSGreg Roach * @param string $sex 131323788f4SGreg Roach * 13201ffdfd0SGreg Roach * @return array<int,string> 133323788f4SGreg Roach */ 134cb7a42eaSGreg Roach public function newSpouseNames(Individual $spouse, string $sex): array 135c1010edaSGreg Roach { 136cb7a42eaSGreg Roach return [ 13788a03560SGreg Roach $this->buildName('', ['TYPE' => NameType::VALUE_BIRTH]), 138cb7a42eaSGreg Roach ]; 139323788f4SGreg Roach } 140323788f4SGreg Roach} 141