[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Russian (русский язык) 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 * @ingroup Language 22 */ 23 24 /** 25 * Russian (русский язык) 26 * 27 * You can contact Alexander Sigachov (alexander.sigachov at Googgle Mail) 28 * 29 * @ingroup Language 30 */ 31 class LanguageRu extends Language { 32 33 /** 34 * Convert from the nominative form of a noun to some other case 35 * Invoked with {{grammar:case|word}} 36 * 37 * @param string $word 38 * @param string $case 39 * @return string 40 */ 41 function convertGrammar( $word, $case ) { 42 global $wgGrammarForms; 43 if ( isset( $wgGrammarForms['ru'][$case][$word] ) ) { 44 return $wgGrammarForms['ru'][$case][$word]; 45 } 46 47 # These rules are not perfect, but they are currently only used for Wikimedia 48 # site names so it doesn't matter if they are wrong sometimes. 49 # Just add a special case for your site name if necessary. 50 51 # substr doesn't support Unicode and mb_substr has issues, 52 # so break it to characters using preg_match_all and then use array_slice and join 53 $chars = array(); 54 preg_match_all( '/./us', $word, $chars ); 55 if ( !preg_match( "/[a-zA-Z_]/us", $word ) ) { 56 switch ( $case ) { 57 case 'genitive': # родительный падеж 58 if ( join( '', array_slice( $chars[0], -1 ) ) === 'ь' ) { 59 $word = join( '', array_slice( $chars[0], 0, -1 ) ) . 'я'; 60 } elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ия' ) { 61 $word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'ии'; 62 } elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ка' ) { 63 $word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'ки'; 64 } elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ти' ) { 65 $word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'тей'; 66 } elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ды' ) { 67 $word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'дов'; 68 } elseif ( join( '', array_slice( $chars[0], -1 ) ) === 'д' ) { 69 $word = join( '', array_slice( $chars[0], 0, -1 ) ) . 'да'; 70 } elseif ( join( '', array_slice( $chars[0], -3 ) ) === 'ник' ) { 71 $word = join( '', array_slice( $chars[0], 0, -3 ) ) . 'ника'; 72 } elseif ( join( '', array_slice( $chars[0], -3 ) ) === 'ные' ) { 73 $word = join( '', array_slice( $chars[0], 0, -3 ) ) . 'ных'; 74 } 75 break; 76 case 'dative': # дательный падеж 77 # stub 78 break; 79 case 'accusative': # винительный падеж 80 # stub 81 break; 82 case 'instrumental': # творительный падеж 83 # stub 84 break; 85 case 'prepositional': # предложный падеж 86 if ( join( '', array_slice( $chars[0], -1 ) ) === 'ь' ) { 87 $word = join( '', array_slice( $chars[0], 0, -1 ) ) . 'е'; 88 } elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ия' ) { 89 $word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'ии'; 90 } elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ка' ) { 91 $word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'ке'; 92 } elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ти' ) { 93 $word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'тях'; 94 } elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ды' ) { 95 $word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'дах'; 96 } elseif ( join( '', array_slice( $chars[0], -1 ) ) === 'д' ) { 97 $word = join( '', array_slice( $chars[0], 0, -1 ) ) . 'де'; 98 } elseif ( join( '', array_slice( $chars[0], -3 ) ) === 'ник' ) { 99 $word = join( '', array_slice( $chars[0], 0, -3 ) ) . 'нике'; 100 } elseif ( join( '', array_slice( $chars[0], -3 ) ) === 'ные' ) { 101 $word = join( '', array_slice( $chars[0], 0, -3 ) ) . 'ных'; 102 } 103 break; 104 } 105 } 106 107 return $word; 108 } 109 110 /** 111 * Four-digit number should be without group commas (spaces) 112 * See manual of style at http://ru.wikipedia.org/wiki/Википедия:Оформление_статей 113 * So "1 234 567", "12 345" but "1234" 114 * 115 * @param string $_ 116 * 117 * @return string 118 */ 119 function commafy( $_ ) { 120 if ( preg_match( '/^-?\d{1,4}(\.\d*)?$/', $_ ) ) { 121 return $_; 122 } else { 123 return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) ); 124 } 125 } 126 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |