LanguageRu.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. * Russian (русский язык)
  25. *
  26. * You can contact:
  27. * Alexander Sigachov (alexander.sigachov at Googgle Mail)
  28. * Amir E. Aharoni (amir.aharoni@mail.huji.ac.il)
  29. *
  30. * @ingroup Language
  31. */
  32. class LanguageRu extends Language {
  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. $grammarTransformations = $this->getGrammarTransformations();
  47. if ( isset( $grammarTransformations[$case] ) ) {
  48. foreach ( array_values( $grammarTransformations[$case] ) as $rule ) {
  49. $form = $rule[0];
  50. if ( $form === '@metadata' ) {
  51. continue;
  52. }
  53. $replacement = $rule[1];
  54. $regex = "/$form/";
  55. if ( preg_match( $regex, $word ) ) {
  56. $word = preg_replace( $regex, $replacement, $word );
  57. break;
  58. }
  59. }
  60. }
  61. return $word;
  62. }
  63. /**
  64. * Four-digit number should be without group commas (spaces)
  65. * See manual of style at https://ru.wikipedia.org/wiki/Википедия:Оформление_статей
  66. * So "1 234 567", "12 345" but "1234"
  67. *
  68. * @param string $_
  69. *
  70. * @return string
  71. */
  72. function commafy( $_ ) {
  73. if ( preg_match( '/^-?\d{1,4}(\.\d*)?$/', $_ ) ) {
  74. return $_;
  75. } else {
  76. return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) );
  77. }
  78. }
  79. }