LanguageUk.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /** Ukrainian (українська мова)
  3. *
  4. * @ingroup Language
  5. */
  6. class LanguageUk extends Language {
  7. # Convert from the nominative form of a noun to some other case
  8. # Invoked with {{grammar:case|word}}
  9. function convertGrammar( $word, $case ) {
  10. global $wgGrammarForms;
  11. if ( isset($wgGrammarForms['uk'][$case][$word]) ) {
  12. return $wgGrammarForms['uk'][$case][$word];
  13. }
  14. # These rules are not perfect, but they are currently only used for site names so it doesn't
  15. # matter if they are wrong sometimes. Just add a special case for your site name if necessary.
  16. #join and array_slice instead mb_substr
  17. $ar = array();
  18. preg_match_all( '/./us', $word, $ar );
  19. if (!preg_match("/[a-zA-Z_]/us", $word))
  20. switch ( $case ) {
  21. case 'genitive': #родовий відмінок
  22. if ((join('',array_slice($ar[0],-4))=='вікі') || (join('',array_slice($ar[0],-4))=='Вікі'))
  23. {}
  24. elseif (join('',array_slice($ar[0],-1))=='ь')
  25. $word = join('',array_slice($ar[0],0,-1)).'я';
  26. elseif (join('',array_slice($ar[0],-2))=='ія')
  27. $word=join('',array_slice($ar[0],0,-2)).'ії';
  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],-3))=='ник')
  35. $word=join('',array_slice($ar[0],0,-3)).'ника';
  36. break;
  37. case 'dative': #давальний відмінок
  38. #stub
  39. break;
  40. case 'accusative': #знахідний відмінок
  41. if ((join('',array_slice($ar[0],-4))=='вікі') || (join('',array_slice($ar[0],-4))=='Вікі'))
  42. {}
  43. elseif (join('',array_slice($ar[0],-2))=='ія')
  44. $word=join('',array_slice($ar[0],0,-2)).'ію';
  45. break;
  46. case 'instrumental': #орудний відмінок
  47. #stub
  48. break;
  49. case 'prepositional': #місцевий відмінок
  50. #stub
  51. break;
  52. }
  53. return $word;
  54. }
  55. function convertPlural( $count, $forms ) {
  56. if ( !count($forms) ) { return ''; }
  57. //if no number with word, then use $form[0] for singular and $form[1] for plural or zero
  58. if( count($forms) === 2 ) return $count == 1 ? $forms[0] : $forms[1];
  59. $forms = $this->preConvertPlural( $forms, 3 );
  60. if ($count > 10 && floor(($count % 100) / 10) == 1) {
  61. return $forms[2];
  62. } else {
  63. switch ($count % 10) {
  64. case 1: return $forms[0];
  65. case 2:
  66. case 3:
  67. case 4: return $forms[1];
  68. default: return $forms[2];
  69. }
  70. }
  71. }
  72. /*
  73. * Ukrainian numeric format is "12 345,67" but "1234,56"
  74. */
  75. function commafy($_) {
  76. if (!preg_match('/^\d{1,4}$/',$_)) {
  77. return strrev((string)preg_replace('/(\d{3})(?=\d)(?!\d*\.)/','$1,',strrev($_)));
  78. } else {
  79. return $_;
  80. }
  81. }
  82. }