LanguageRu.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /** Russian (русский язык)
  3. *
  4. * You can contact Alexander Sigachov (alexander.sigachov at Googgle Mail)
  5. *
  6. * @ingroup Language
  7. */
  8. class LanguageRu extends Language {
  9. # Convert from the nominative form of a noun to some other case
  10. # Invoked with {{grammar:case|word}}
  11. function convertGrammar( $word, $case ) {
  12. global $wgGrammarForms;
  13. if ( isset($wgGrammarForms['ru'][$case][$word]) ) {
  14. return $wgGrammarForms['ru'][$case][$word];
  15. }
  16. # These rules are not perfect, but they are currently only used for site names so it doesn't
  17. # matter if they are wrong sometimes. Just add a special case for your site name if necessary.
  18. #join and array_slice instead mb_substr
  19. $ar = array();
  20. preg_match_all( '/./us', $word, $ar );
  21. if (!preg_match("/[a-zA-Z_]/us", $word))
  22. switch ( $case ) {
  23. case 'genitive': #родительный падеж
  24. if ((join('',array_slice($ar[0],-4))=='вики') || (join('',array_slice($ar[0],-4))=='Вики'))
  25. {}
  26. elseif (join('',array_slice($ar[0],-1))=='ь')
  27. $word = join('',array_slice($ar[0],0,-1)).'я';
  28. elseif (join('',array_slice($ar[0],-2))=='ия')
  29. $word=join('',array_slice($ar[0],0,-2)).'ии';
  30. elseif (join('',array_slice($ar[0],-2))=='ка')
  31. $word=join('',array_slice($ar[0],0,-2)).'ки';
  32. elseif (join('',array_slice($ar[0],-2))=='ти')
  33. $word=join('',array_slice($ar[0],0,-2)).'тей';
  34. elseif (join('',array_slice($ar[0],-2))=='ды')
  35. $word=join('',array_slice($ar[0],0,-2)).'дов';
  36. elseif (join('',array_slice($ar[0],-3))=='ник')
  37. $word=join('',array_slice($ar[0],0,-3)).'ника';
  38. break;
  39. case 'dative': #дательный падеж
  40. #stub
  41. break;
  42. case 'accusative': #винительный падеж
  43. #stub
  44. break;
  45. case 'instrumental': #творительный падеж
  46. #stub
  47. break;
  48. case 'prepositional': #предложный падеж
  49. #stub
  50. break;
  51. }
  52. return $word;
  53. }
  54. /**
  55. * Plural form transformations
  56. *
  57. * $forms[0] - singular form (for 1, 21, 31, 41...)
  58. * $forms[1] - paucal form (for 2, 3, 4, 22, 23, 24, 32, 33, 34...)
  59. * $forms[2] - plural form (for 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 26...)
  60. *
  61. * Examples:
  62. * message with number
  63. * "Сделано $1 {{PLURAL:$1|изменение|изменения|изменений}}"
  64. * message without number
  65. * "Действие не может быть выполнено по {{PLURAL:$1|следующей причине|следующим причинам}}:"
  66. *
  67. */
  68. function convertPlural( $count, $forms ) {
  69. if ( !count($forms) ) { return ''; }
  70. //if no number with word, then use $form[0] for singular and $form[1] for plural or zero
  71. if( count($forms) === 2 ) return $count == 1 ? $forms[0] : $forms[1];
  72. $forms = $this->preConvertPlural( $forms, 3 );
  73. if ($count > 10 && floor(($count % 100) / 10) == 1) {
  74. return $forms[2];
  75. } else {
  76. switch ($count % 10) {
  77. case 1: return $forms[0];
  78. case 2:
  79. case 3:
  80. case 4: return $forms[1];
  81. default: return $forms[2];
  82. }
  83. }
  84. }
  85. /*
  86. * Four-digit number should be without group commas (spaces)
  87. * See manual of style at http://ru.wikipedia.org/wiki/Википедия:Оформление_статей
  88. * So "1 234 567", "12 345" but "1234"
  89. */
  90. function commafy($_) {
  91. if (preg_match('/^-?\d{1,4}(\.\d*)?$/',$_)) {
  92. return $_;
  93. } else {
  94. return strrev((string)preg_replace('/(\d{3})(?=\d)(?!\d*\.)/','$1,',strrev($_)));
  95. }
  96. }
  97. }