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\Statistics\Service; 21 22use Fisharebest\Webtrees\I18N; 23 24/** 25 * Functions for managing centuries. 26 */ 27class CenturyService 28{ 29 /** 30 * Century name, English => 21st, Polish => XXI, etc. 31 * 32 * @param int $century 33 * 34 * @return string 35 */ 36 public function centuryName(int $century): string 37 { 38 if ($century < 0) { 39 return I18N::translate('%s BCE', $this->centuryName(-$century)); 40 } 41 42 // The current chart engine (Google charts) can't handle <sup></sup> markup 43 switch ($century) { 44 case 21: 45 return strip_tags(I18N::translateContext('CENTURY', '21st')); 46 case 20: 47 return strip_tags(I18N::translateContext('CENTURY', '20th')); 48 case 19: 49 return strip_tags(I18N::translateContext('CENTURY', '19th')); 50 case 18: 51 return strip_tags(I18N::translateContext('CENTURY', '18th')); 52 case 17: 53 return strip_tags(I18N::translateContext('CENTURY', '17th')); 54 case 16: 55 return strip_tags(I18N::translateContext('CENTURY', '16th')); 56 case 15: 57 return strip_tags(I18N::translateContext('CENTURY', '15th')); 58 case 14: 59 return strip_tags(I18N::translateContext('CENTURY', '14th')); 60 case 13: 61 return strip_tags(I18N::translateContext('CENTURY', '13th')); 62 case 12: 63 return strip_tags(I18N::translateContext('CENTURY', '12th')); 64 case 11: 65 return strip_tags(I18N::translateContext('CENTURY', '11th')); 66 case 10: 67 return strip_tags(I18N::translateContext('CENTURY', '10th')); 68 case 9: 69 return strip_tags(I18N::translateContext('CENTURY', '9th')); 70 case 8: 71 return strip_tags(I18N::translateContext('CENTURY', '8th')); 72 case 7: 73 return strip_tags(I18N::translateContext('CENTURY', '7th')); 74 case 6: 75 return strip_tags(I18N::translateContext('CENTURY', '6th')); 76 case 5: 77 return strip_tags(I18N::translateContext('CENTURY', '5th')); 78 case 4: 79 return strip_tags(I18N::translateContext('CENTURY', '4th')); 80 case 3: 81 return strip_tags(I18N::translateContext('CENTURY', '3rd')); 82 case 2: 83 return strip_tags(I18N::translateContext('CENTURY', '2nd')); 84 case 1: 85 return strip_tags(I18N::translateContext('CENTURY', '1st')); 86 default: 87 return ($century - 1) . '01-' . $century . '00'; 88 } 89 } 90} 91