Debian Codegraph @

includes/languages/LanguageZh_hans.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20 // phpcs:ignoreFile Squiz.Classes.ValidClassName.NotCamelCaps
21
22 use MediaWiki\Language\Language;
23
24 /**
25 * Simplified Chinese
26 *
27 * @ingroup Languages
28 */
29 class LanguageZh_hans extends Language {
30
31 private const WORD_SEGMENTATION_REGEX = '/([\xc0-\xff][\x80-\xbf]*)/';
32
33 public function hasWordBreaks() {
34 return false;
35 }
36
37 /**
38 * @todo FIXME: Only do this for Han characters...
39 *
40 * @inheritDoc
41 */
42 public function segmentByWord( $string ) {
43 return self::insertSpace( $string, self::WORD_SEGMENTATION_REGEX );
44 }
45
46 public function normalizeForSearch( $s ) {
47 // Double-width roman characters
48 $s = parent::normalizeForSearch( $s );
49 $s = trim( $s );
50 return $this->segmentByWord( $s );
51 }
52
53 public function formatDuration( $seconds, array $chosenIntervals = [] ) {
54 if ( !$chosenIntervals ) {
55 $chosenIntervals = [ 'centuries', 'years', 'days', 'hours', 'minutes', 'seconds' ];
56 }
57
58 $intervals = $this->getDurationIntervals( $seconds, $chosenIntervals );
59
60 $segments = [];
61
62 foreach ( $intervals as $intervalName => $intervalValue ) {
63 // Messages: duration-seconds, duration-minutes, duration-hours, duration-days, duration-weeks,
64 // duration-years, duration-decades, duration-centuries, duration-millennia
65 $message = wfMessage( 'duration-' . $intervalName )->numParams( $intervalValue );
66 $segments[] = $message->inLanguage( $this )->escaped();
67 }
68
69 return implode( '', $segments );
70 }
71 }