From: Amir E. Aharoni Date: Sun, 11 Oct 2015 19:35:28 +0000 (+0300) Subject: Move the Ukrainian grammar rules from PHP and JS to JSON X-Git-Tag: 1.31.0-rc.0~4517^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/pie.php?a=commitdiff_plain;h=58612ee9fa3c212b30fdfc20a1856e0dedfec61f;p=lhc%2Fweb%2Fwiklou.git Move the Ukrainian grammar rules from PHP and JS to JSON Bug: T115217 Change-Id: I15a06b07e381cc9074e64e746d22ec51e9e638c4 --- diff --git a/languages/classes/LanguageUk.php b/languages/classes/LanguageUk.php index 72bde4007d..a155d036f3 100644 --- a/languages/classes/LanguageUk.php +++ b/languages/classes/LanguageUk.php @@ -27,50 +27,6 @@ * @ingroup Language */ class LanguageUk extends Language { - - /** - * Convert from the nominative form of a noun to some other case - * Invoked with {{grammar:case|word}} - * - * @param string $word - * @param string $case - * @return string - */ - function convertGrammar( $word, $case ) { - global $wgGrammarForms; - if ( isset( $wgGrammarForms['uk'][$case][$word] ) ) { - return $wgGrammarForms['uk'][$case][$word]; - } - - # These rules don't cover the whole language. - # They are used only for site names. - - # join and array_slice instead mb_substr - $ar = []; - preg_match_all( '/./us', $word, $ar ); - if ( !preg_match( "/[a-zA-Z_]/us", $word ) ) { - switch ( $case ) { - case 'genitive': # родовий відмінок - if ( implode( '', array_slice( $ar[0], -2 ) ) === 'ія' ) { - $word = implode( '', array_slice( $ar[0], 0, -2 ) ) . 'ії'; - } elseif ( implode( '', array_slice( $ar[0], -2 ) ) === 'ти' ) { - $word = implode( '', array_slice( $ar[0], 0, -2 ) ) . 'т'; - } elseif ( implode( '', array_slice( $ar[0], -2 ) ) === 'ди' ) { - $word = implode( '', array_slice( $ar[0], 0, -2 ) ) . 'дів'; - } elseif ( implode( '', array_slice( $ar[0], -3 ) ) === 'ник' ) { - $word = implode( '', array_slice( $ar[0], 0, -3 ) ) . 'ника'; - } - break; - case 'accusative': # знахідний відмінок - if ( implode( '', array_slice( $ar[0], -2 ) ) === 'ія' ) { - $word = implode( '', array_slice( $ar[0], 0, -2 ) ) . 'ію'; - } - break; - } - } - return $word; - } - /** * Ukrainian numeric format is "12 345,67" but "1234,56" * diff --git a/languages/data/grammarTransformations/uk.json b/languages/data/grammarTransformations/uk.json new file mode 100644 index 0000000000..6512225d87 --- /dev/null +++ b/languages/data/grammarTransformations/uk.json @@ -0,0 +1,18 @@ +{ + "@metadata": { + "authors": [ + "Gutsul", + "Amir E. Aharoni (amir.aharoni@mail.huji.ac.il)" + ], + "comment": "These rules don't cover the whole grammar of the language, and are intended only for names of languages and Wikimedia projects." + }, + "genitive": [ + [ "(.+)ія$", "$1ії" ], + [ "(.+)ти$", "$1т" ], + [ "(.+)ди$", "$1дів" ], + [ "(.+)ник$", "$1ника" ] + ], + "accusative": [ + [ "(.+)ія$", "$1ію" ] + ] +} diff --git a/resources/Resources.php b/resources/Resources.php index 3fef2ccc5d..e8be528889 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -1597,7 +1597,6 @@ return [ 'la' => 'resources/src/mediawiki.language/languages/la.js', 'os' => 'resources/src/mediawiki.language/languages/os.js', 'sl' => 'resources/src/mediawiki.language/languages/sl.js', - 'uk' => 'resources/src/mediawiki.language/languages/uk.js', ], 'dependencies' => [ 'mediawiki.language.data', diff --git a/resources/src/mediawiki.language/languages/uk.js b/resources/src/mediawiki.language/languages/uk.js deleted file mode 100644 index 138045c658..0000000000 --- a/resources/src/mediawiki.language/languages/uk.js +++ /dev/null @@ -1,32 +0,0 @@ -/*! - * Ukrainian (Українська) language functions - */ - -mediaWiki.language.convertGrammar = function ( word, form ) { - var grammarForms = mediaWiki.language.getData( 'uk', 'grammarForms' ); - if ( grammarForms && grammarForms[ form ] ) { - return grammarForms[ form ][ word ]; - } - switch ( form ) { - case 'genitive': // родовий відмінок - if ( word.slice( -2 ) === 'ія' ) { - word = word.slice( 0, -2 ) + 'ії'; - } else if ( word.slice( -2 ) === 'ти' ) { - word = word.slice( 0, -2 ) + 'т'; - } else if ( word.slice( -2 ) === 'ди' ) { - word = word.slice( 0, -2 ) + 'дів'; - } else if ( word.slice( -3 ) === 'ник' ) { - word = word.slice( 0, -3 ) + 'ника'; - } - - break; - case 'accusative': // знахідний відмінок - if ( word.slice( -2 ) === 'ія' ) { - word = word.slice( 0, -2 ) + 'ію'; - } - - break; - } - - return word; -};