Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| GrammarCu | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 1 |
| process | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
42 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace Wikimedia\Leximorph\Handler\Overrides\Grammar; |
| 8 | |
| 9 | use Wikimedia\Leximorph\Handler\Overrides\IGrammarTransformer; |
| 10 | |
| 11 | /** |
| 12 | * GrammarCu |
| 13 | * |
| 14 | * Implements grammar transformations for Church Slavonic (cu). |
| 15 | * |
| 16 | * These rules don't cover the whole grammar of the language. |
| 17 | * This logic was originally taken from MediaWiki Core. |
| 18 | * Thanks to all contributors. |
| 19 | * |
| 20 | * @since 1.45 |
| 21 | * @author Doğu Abaris (abaris@null.net) |
| 22 | * @license https://www.gnu.org/copyleft/gpl.html GPL-2.0-or-later |
| 23 | */ |
| 24 | class GrammarCu implements IGrammarTransformer { |
| 25 | /** |
| 26 | * Applies Church Slavonic-specific grammatical transformations. |
| 27 | * |
| 28 | * @param string $word The word to process. |
| 29 | * @param string $case The grammatical case. |
| 30 | * |
| 31 | * @since 1.45 |
| 32 | * @return string The processed word. |
| 33 | */ |
| 34 | public function process( string $word, string $case ): string { |
| 35 | # These rules are not perfect, but they are currently only used for |
| 36 | # site names, so it doesn't matter if they are wrong sometimes. |
| 37 | # Just add a special case for your site name if necessary. |
| 38 | |
| 39 | # join and array_slice instead mb_substr |
| 40 | $ar = []; |
| 41 | preg_match_all( '/./us', $word, $ar ); |
| 42 | if ( !preg_match( "/[a-zA-Z_]/u", $word ) ) { |
| 43 | switch ( $case ) { |
| 44 | # родительный падеж |
| 45 | case 'genitive': |
| 46 | // if ( ( implode( '', array_slice( $ar[0], -4 ) ) == 'вики' ) |
| 47 | // || ( implode( '', array_slice( $ar[0], -4 ) ) == 'Вики' ) |
| 48 | // ) { |
| 49 | // } |
| 50 | |
| 51 | if ( implode( '', array_slice( $ar[0], -2 ) ) == 'ї' ) { |
| 52 | return implode( '', array_slice( $ar[0], 0, -2 ) ) . 'їѩ'; |
| 53 | } |
| 54 | break; |
| 55 | # винительный падеж |
| 56 | case 'accusative': |
| 57 | # stub |
| 58 | break; |
| 59 | |
| 60 | default: |
| 61 | break; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | return $word; |
| 66 | } |
| 67 | } |