Merge "Plural rules: updates for UTS #35 Rev 33"
[lhc/web/wiklou.git] / languages / classes / LanguageBe_tarask.php
1 <?php
2 /**
3 * Belarusian in Taraškievica orthography (Беларуская тарашкевіца) specific code.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
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 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
23 * @license http://www.gnu.org/copyleft/fdl.html GNU Free Documentation License
24 * @ingroup Language
25 */
26
27 /**
28 * Belarusian in Taraškievica orthography (Беларуская тарашкевіца)
29 *
30 * @ingroup Language
31 * @see http://be-x-old.wikipedia.org/wiki/Project_talk:LanguageBe_tarask.php
32 */
33 class LanguageBe_tarask extends Language {
34 /**
35 * Plural form transformations
36 *
37 * $wordform1 - singular form (for 1, 21, 31, 41...)
38 * $wordform2 - plural form (for 2, 3, 4, 22, 23, 24, 32, 33, 34...)
39 * $wordform3 - plural form (for 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 26...)
40 */
41
42 /**
43 * @param $count int
44 * @param $forms array
45 *
46 * @return string
47 */
48 function convertPlural( $count, $forms ) {
49 $forms = $this->handleExplicitPluralForms( $count, $forms );
50 if ( is_string( $forms ) ) {
51 return $forms;
52 }
53 if ( !count( $forms ) ) {
54 return '';
55 }
56
57 // If the actual number is not mentioned in the expression, then just two forms are enough:
58 // singular for $count == 1
59 // plural for $count != 1
60 // For example, "This user belongs to {{PLURAL:$1|one group|several groups}}."
61 if ( count( $forms ) === 2 ) {
62 return $count == 1 ? $forms[0] : $forms[1];
63 }
64
65 // @todo FIXME: CLDR defines 4 plural forms instead of 3
66 // http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
67 $forms = $this->preConvertPlural( $forms, 3 );
68
69 if ( $count > 10 && floor( ( $count % 100 ) / 10 ) == 1 ) {
70 return $forms[2];
71 } else {
72 switch ( $count % 10 ) {
73 case 1: return $forms[0];
74 case 2:
75 case 3:
76 case 4: return $forms[1];
77 default: return $forms[2];
78 }
79 }
80 }
81
82 /**
83 * The Belarusian language uses apostrophe sign,
84 * but the characters used for this could be both U+0027 and U+2019.
85 * This function unifies apostrophe sign in search index values
86 * to enable seach using both apostrophe signs.
87 *
88 * @param $string string
89 *
90 * @return string
91 */
92 function normalizeForSearch( $string ) {
93 wfProfileIn( __METHOD__ );
94
95 # MySQL fulltext index doesn't grok utf-8, so we
96 # need to fold cases and convert to hex
97
98 # Replacing apostrophe sign U+2019 with U+0027
99 $s = preg_replace( '/\xe2\x80\x99/', '\'', $string );
100
101 $s = parent::normalizeForSearch( $s );
102
103 wfProfileOut( __METHOD__ );
104 return $s;
105 }
106
107 /**
108 * Four-digit number should be without group commas (spaces)
109 * So "1 234 567", "12 345" but "1234"
110 *
111 * @param $_ string
112 *
113 * @return string
114 */
115 function commafy( $_ ) {
116 if ( preg_match( '/^-?\d{1,4}(\.\d*)?$/', $_ ) ) {
117 return $_;
118 } else {
119 return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) );
120 }
121 }
122 }