| [ PHPXref.com ] | [ Generated: Sun Jul 20 19:05:09 2008 ] | [ onPHP 0.4.6 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /*************************************************************************** 3 * Copyright (C) 2004-2005 by Sveta Smirnova * 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 ***************************************************************************/ 11 /* $Id: RussianTextUtils.class.php 1684 2006-06-10 20:58:39Z voxus $ */ 12 13 /** 14 * @ingroup Utils 15 **/ 16 final class RussianTextUtils extends StaticFactory 17 { 18 const MALE = 0; 19 const FEMALE = 1; 20 const NEUTRAL = 2; 21 22 // TODO: deprecated by selectCaseForNumber 23 private static $secondDecade = array(11, 12, 13, 14, 15, 16, 17, 18, 19); 24 25 private static $orderedSuffixes = array( 26 self::MALE => array('ый', 'ой', 'ий'), 27 self::FEMALE => array('ая', 'ья', null), 28 self::NEUTRAL => array('ое', 'ье', null) 29 ); 30 31 private static $orederedDigits = array( 32 'перв', 33 'втор', 34 'трет', 35 'четвёрт', 36 'пят', 37 'шест', 38 'седьм', 39 'восьм', 40 'девят', 41 'десят', 42 ); 43 44 /** 45 * Returns text representation of digit 46 **/ 47 public static function getAsText($number, $gender) 48 { 49 throw new UnsupportedMethodException(); 50 } 51 52 /** 53 * Returns suffix for word 54 * 55 * @deprecated by selectCaseForNumber 56 * @param $number integer variable 57 * @param $suffixes array of suffixes as array('ца', 'цы', null) 58 **/ 59 public static function getSuffix($number, $suffixes) 60 { 61 if ( 62 in_array( 63 intval(substr($number, strlen($number) - 2, 2)), 64 self::$secondDecade, true 65 ) 66 ) { 67 return $suffixes[2]; 68 } 69 70 $lastDigit = substr($number, strlen($number) - 1, 1); 71 72 switch ($lastDigit) { 73 case '1': 74 return $suffixes[0]; 75 76 case '2': 77 case '3': 78 case '4': 79 return $suffixes[1]; 80 81 default: 82 return $suffixes[2]; 83 } 84 } 85 86 /** 87 * Select russian case for number 88 * for example: 89 * 1 результат 90 * 2 результата 91 * 5 результатов 92 * @param $number integer 93 * @param $cases words to select from array('результат', 'результата', 'результатов') 94 */ 95 public static function selectCaseForNumber($number, $cases) 96 { 97 if (($number % 10) == 1 && ($number % 100) != 11) { 98 99 return $cases[0]; 100 101 } elseif ( 102 ($number % 10) > 1 103 && ($number % 10) < 5 104 && ($number < 10 || $number > 20) 105 ) { 106 107 return $cases[1]; 108 109 } else { 110 return $cases[2]; 111 } 112 } 113 114 /** 115 * doesn't duplicate strtolower('%B', ...) 116 * only when 'russian' locale set in windoze 117 **/ 118 public static function getMonthInGenitiveCase($month) 119 { 120 static $months = array( 121 'января', 'февраля', 'марта', 'апреля', 122 'мая', 'июня', 'июля', 'августа', 'сентября', 123 'октября', 'ноября', 'декабря' 124 ); 125 126 return $months[$month - 1]; 127 } 128 129 public static function getMonthInSubjectiveCase($month) 130 { 131 static $months = array( 132 'январь', 'февраль', 'март', 'апрель', 133 'май', 'июнь', 'июль', 'август', 'сентябрь', 134 'октябрь', 'ноябрь', 'декабрь' 135 ); 136 137 return $months[$month - 1]; 138 } 139 140 public static function getDayOfWeek($day) 141 { 142 static $weekDays = array( 143 'вс', 'пн', 'вт', 'ср', 144 'чт', 'пт', 'сб', 'вс' 145 ); 146 147 return $weekDays[$day]; 148 } 149 } 150 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |