Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
LanguageZh_hans
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 4
42
0.00% covered (danger)
0.00%
0 / 1
 hasWordBreaks
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 segmentByWord
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 normalizeForSearch
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 formatDuration
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
12
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/**
23 * Simplified Chinese
24 *
25 * @ingroup Languages
26 */
27class LanguageZh_hans extends Language {
28    public function hasWordBreaks() {
29        return false;
30    }
31
32    /**
33     * @todo FIXME: Only do this for Han characters...
34     *
35     * @inheritDoc
36     */
37    public function segmentByWord( $string ) {
38        $reg = "/([\\xc0-\\xff][\\x80-\\xbf]*)/";
39        return self::insertSpace( $string, $reg );
40    }
41
42    public function normalizeForSearch( $s ) {
43        // Double-width roman characters
44        $s = parent::normalizeForSearch( $s );
45        $s = trim( $s );
46        return $this->segmentByWord( $s );
47    }
48
49    public function formatDuration( $seconds, array $chosenIntervals = [] ) {
50        if ( !$chosenIntervals ) {
51            $chosenIntervals = [ 'centuries', 'years', 'days', 'hours', 'minutes', 'seconds' ];
52        }
53
54        $intervals = $this->getDurationIntervals( $seconds, $chosenIntervals );
55
56        $segments = [];
57
58        foreach ( $intervals as $intervalName => $intervalValue ) {
59            // Messages: duration-seconds, duration-minutes, duration-hours, duration-days, duration-weeks,
60            // duration-years, duration-decades, duration-centuries, duration-millennia
61            $message = wfMessage( 'duration-' . $intervalName )->numParams( $intervalValue );
62            $segments[] = $message->inLanguage( $this )->escaped();
63        }
64
65        return implode( '', $segments );
66    }
67}