wiki.techinc.nl/languages/classes/LanguageRu.php

127 lines
4.9 KiB
PHP
Raw Normal View History

<?php
/**
* Russian (русский язык) specific code.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup Language
*/
/**
* Russian (русский язык)
*
* You can contact Alexander Sigachov (alexander.sigachov at Googgle Mail)
*
* @ingroup Language
*/
Merged localisation-work branch: * Made lines from initialiseMessages() appear as list items during installation * Moved the bulk of the localisation data from the Language*.php files to the Messages*.php files. Deleted most of the Languages*.php files. * Introduced "stub global" framework to provide deferred initialisation of core modules. * Removed placeholder values for $wgTitle and $wgArticle, these variables will now be null during the initialisation process, until they are set by index.php or another entry point. * Added DBA cache type, for BDB-style caches. * Removed custom date format functions, replacing them with a format string in the style of PHP's date(). Used string identifiers instead of integer identifiers, in both the language files and user preferences. Migration should be transparent in most cases. * Simplified the initialisation API for LoadBalancer objects. * Removed the broken altencoding feature. * Moved default user options and toggles from Language to User. Language objects are still able to define default preference overrides and extra user toggles, via a slightly different interface. * Don't include the date option in the parser cache rendering hash unless $wgUseDynamicDates is enabled. * Merged LanguageUtf8 with Language. Removed LanguageUtf8.php. * Removed inclusion of language files from the bottom of Language.php. This is now consistently done from Language::factory(). * Add the name of the executing maintenance script to the debug log. Start the profiler during maintenance scripts. * Added "serialized" directory, for storing precompiled data in serialized form.
2006-07-26 07:15:39 +00:00
class LanguageRu extends Language {
2011-05-29 16:32:05 +00:00
/**
* Convert from the nominative form of a noun to some other case
* Invoked with {{grammar:case|word}}
*
* @param string $word
* @param string $case
2011-05-29 16:32:05 +00:00
* @return string
*/
function convertGrammar( $word, $case ) {
global $wgGrammarForms;
if ( isset( $wgGrammarForms['ru'][$case][$word] ) ) {
return $wgGrammarForms['ru'][$case][$word];
}
# These rules are not perfect, but they are currently only used for Wikimedia
# site names so it doesn't matter if they are wrong sometimes.
# Just add a special case for your site name if necessary.
# substr doesn't support Unicode and mb_substr has issues,
# so break it to characters using preg_match_all and then use array_slice and join
$chars = array();
preg_match_all( '/./us', $word, $chars );
if ( !preg_match( "/[a-zA-Z_]/us", $word ) ) {
switch ( $case ) {
case 'genitive': # родительный падеж
if ( join( '', array_slice( $chars[0], -1 ) ) === 'ь' ) {
$word = join( '', array_slice( $chars[0], 0, -1 ) ) . 'я';
} elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ия' ) {
$word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'ии';
} elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ка' ) {
$word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'ки';
} elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ти' ) {
$word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'тей';
} elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ды' ) {
$word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'дов';
} elseif ( join( '', array_slice( $chars[0], -1 ) ) === 'д' ) {
$word = join( '', array_slice( $chars[0], 0, -1 ) ) . 'да';
} elseif ( join( '', array_slice( $chars[0], -3 ) ) === 'ник' ) {
$word = join( '', array_slice( $chars[0], 0, -3 ) ) . 'ника';
} elseif ( join( '', array_slice( $chars[0], -3 ) ) === 'ные' ) {
$word = join( '', array_slice( $chars[0], 0, -3 ) ) . 'ных';
}
break;
case 'dative': # дательный падеж
# stub
break;
case 'accusative': # винительный падеж
# stub
break;
case 'instrumental': # творительный падеж
# stub
break;
case 'prepositional': # предложный падеж
if ( join( '', array_slice( $chars[0], -1 ) ) === 'ь' ) {
$word = join( '', array_slice( $chars[0], 0, -1 ) ) . 'е';
} elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ия' ) {
$word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'ии';
} elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ка' ) {
$word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'ке';
} elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ти' ) {
$word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'тях';
} elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ды' ) {
$word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'дах';
} elseif ( join( '', array_slice( $chars[0], -1 ) ) === 'д' ) {
$word = join( '', array_slice( $chars[0], 0, -1 ) ) . 'де';
} elseif ( join( '', array_slice( $chars[0], -3 ) ) === 'ник' ) {
$word = join( '', array_slice( $chars[0], 0, -3 ) ) . 'нике';
} elseif ( join( '', array_slice( $chars[0], -3 ) ) === 'ные' ) {
$word = join( '', array_slice( $chars[0], 0, -3 ) ) . 'ных';
}
break;
}
}
return $word;
}
/**
* Four-digit number should be without group commas (spaces)
* See manual of style at http://ru.wikipedia.org/wiki/Википедия:Оформление_статей
* So "1 234 567", "12 345" but "1234"
2011-05-29 15:59:47 +00:00
*
* @param string $_
2011-05-29 15:59:47 +00:00
*
* @return string
2006-01-05 23:51:02 +00:00
*/
function commafy( $_ ) {
if ( preg_match( '/^-?\d{1,4}(\.\d*)?$/', $_ ) ) {
return $_;
} else {
return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) );
}
}
2003-04-14 23:10:40 +00:00
}