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