Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 2 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
LanguageJa | |
0.00% |
0 / 2 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
segmentByWord | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
emphasize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
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 | |
21 | use MediaWiki\Language\Language; |
22 | |
23 | /** |
24 | * Japanese (日本語) |
25 | * |
26 | * @ingroup Languages |
27 | */ |
28 | class LanguageJa extends Language { |
29 | |
30 | /** Space string for hiragana - unicode range U3040-309f */ |
31 | private const WORD_SEG_HIRAGANA = '(?:\xe3(?:\x81[\x80-\xbf]|\x82[\x80-\x9f]))'; |
32 | |
33 | /** Space string for katakana - unicode range U30a0-30ff */ |
34 | private const WORD_SEG_KATAKANA = '(?:\xe3(?:\x82[\xa0-\xbf]|\x83[\x80-\xbf]))'; |
35 | |
36 | /** Space string for kanji - unicode range U3200-9999 = \xe3\x88\x80-\xe9\xa6\x99 */ |
37 | private const WORD_SEG_KANJI = |
38 | '(?:\xe3[\x88-\xbf][\x80-\xbf]|[\xe4-\xe8][\x80-\xbf]{2}|\xe9[\x80-\xa5][\x80-\xbf]|\xe9\xa6[\x80-\x99])'; |
39 | |
40 | private const WORD_SEGMENTATION_REGEX = |
41 | '/(' . self::WORD_SEG_HIRAGANA . '+|' . self::WORD_SEG_KATAKANA . '+|' . self::WORD_SEG_KANJI . '+)/'; |
42 | |
43 | public function segmentByWord( $string ) { |
44 | return self::insertSpace( $string, self::WORD_SEGMENTATION_REGEX ); |
45 | } |
46 | |
47 | /** |
48 | * Italic is not appropriate for Japanese script. |
49 | * Unfortunately, most browsers do not recognise this, and render `<em>` as italic. |
50 | * |
51 | * @param string $text |
52 | * @return string |
53 | */ |
54 | public function emphasize( $text ) { |
55 | return $text; |
56 | } |
57 | } |