Follow up to r109021, corrected the comment, and added a translation from Russian.
[lhc/web/wiklou.git] / languages / classes / LanguageBe_tarask.php
1 <?php
2 /** Belarusian in Taraškievica orthography (Беларуская тарашкевіца)
3 *
4 * @ingroup Language
5 *
6 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
7 * @link http://be-x-old.wikipedia.org/wiki/Project_talk:LanguageBe_tarask.php
8 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
9 * @license http://www.gnu.org/copyleft/fdl.html GNU Free Documentation License
10 */
11
12 class LanguageBe_tarask extends Language {
13 /**
14 * Plural form transformations
15 *
16 * $wordform1 - singular form (for 1, 21, 31, 41...)
17 * $wordform2 - plural form (for 2, 3, 4, 22, 23, 24, 32, 33, 34...)
18 * $wordform3 - plural form (for 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 26...)
19 */
20
21 /**
22 * @param $count int
23 * @param $forms array
24 *
25 * @return string
26 */
27 function convertPlural( $count, $forms ) {
28 if ( !count( $forms ) ) { return ''; }
29
30 // If the actual number is not mentioned in the expression, then just two forms are enough:
31 // singular for $count == 1
32 // plural for $count != 1
33 // For example, "This user belongs to {{PLURAL:$1|one group|several groups}}."
34 if ( count( $forms ) === 2 ) return $count == 1 ? $forms[0] : $forms[1];
35
36 // @todo FIXME: CLDR defines 4 plural forms instead of 3
37 // http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
38 $forms = $this->preConvertPlural( $forms, 3 );
39
40 if ( $count > 10 && floor( ( $count % 100 ) / 10 ) == 1 ) {
41 return $forms[2];
42 } else {
43 switch ( $count % 10 ) {
44 case 1: return $forms[0];
45 case 2:
46 case 3:
47 case 4: return $forms[1];
48 default: return $forms[2];
49 }
50 }
51 }
52
53 /**
54 * The Belarusian language uses apostrophe sign,
55 * but the characters used for this could be both U+0027 and U+2019.
56 * This function unifies apostrophe sign in search index values
57 * to enable seach using both apostrophe signs.
58 *
59 * @param $string string
60 *
61 * @return string
62 */
63 function normalizeForSearch( $string ) {
64 wfProfileIn( __METHOD__ );
65
66 # MySQL fulltext index doesn't grok utf-8, so we
67 # need to fold cases and convert to hex
68
69 # Replacing apostrophe sign U+2019 with U+0027
70 $s = preg_replace( '/\xe2\x80\x99/', '\'', $string );
71
72 $s = parent::normalizeForSearch( $s );
73
74 wfProfileOut( __METHOD__ );
75 return $s;
76 }
77
78 /**
79 * Four-digit number should be without group commas (spaces)
80 * So "1 234 567", "12 345" but "1234"
81 *
82 * @param $_ string
83 *
84 * @return string
85 */
86 function commafy( $_ ) {
87 if ( preg_match( '/^-?\d{1,4}(\.\d*)?$/', $_ ) ) {
88 return $_;
89 } else {
90 return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) );
91 }
92 }
93 }