Add some letters per https://incubator.wikimedia.org/w/index.php?diff=666382&oldid...
[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 no number with word, then use $form[0] for singular and $form[1] for plural or zero
31 if ( count( $forms ) === 2 ) return $count == 1 ? $forms[0] : $forms[1];
32
33 // @todo FIXME: CLDR defines 4 plural forms instead of 3
34 // http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
35 $forms = $this->preConvertPlural( $forms, 3 );
36
37 if ( $count > 10 && floor( ( $count % 100 ) / 10 ) == 1 ) {
38 return $forms[2];
39 } else {
40 switch ( $count % 10 ) {
41 case 1: return $forms[0];
42 case 2:
43 case 3:
44 case 4: return $forms[1];
45 default: return $forms[2];
46 }
47 }
48 }
49
50 /**
51 * The Belarusian language uses apostrophe sign,
52 * but the characters used for this could be both U+0027 and U+2019.
53 * This function unifies apostrophe sign in search index values
54 * to enable seach using both apostrophe signs.
55 *
56 * @param $string string
57 *
58 * @return string
59 */
60 function normalizeForSearch( $string ) {
61 wfProfileIn( __METHOD__ );
62
63 # MySQL fulltext index doesn't grok utf-8, so we
64 # need to fold cases and convert to hex
65
66 # Replacing apostrophe sign U+2019 with U+0027
67 $s = preg_replace( '/\xe2\x80\x99/', '\'', $string );
68
69 $s = parent::normalizeForSearch( $s );
70
71 wfProfileOut( __METHOD__ );
72 return $s;
73 }
74
75 /**
76 * Four-digit number should be without group commas (spaces)
77 * So "1 234 567", "12 345" but "1234"
78 *
79 * @param $_ string
80 *
81 * @return string
82 */
83 function commafy( $_ ) {
84 if ( preg_match( '/^-?\d{1,4}(\.\d*)?$/', $_ ) ) {
85 return $_;
86 } else {
87 return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) );
88 }
89 }
90 }