Move the Ukrainian grammar rules from PHP and JS to JSON
authorAmir E. Aharoni <amir.aharoni@mail.huji.ac.il>
Sun, 11 Oct 2015 19:35:28 +0000 (22:35 +0300)
committerAmire80 <amir.aharoni@mail.huji.ac.il>
Sun, 18 Dec 2016 11:10:16 +0000 (11:10 +0000)
Bug: T115217
Change-Id: I15a06b07e381cc9074e64e746d22ec51e9e638c4

languages/classes/LanguageUk.php
languages/data/grammarTransformations/uk.json [new file with mode: 0644]
resources/Resources.php
resources/src/mediawiki.language/languages/uk.js [deleted file]

index 72bde40..a155d03 100644 (file)
  * @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 (file)
index 0000000..6512225
--- /dev/null
@@ -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ію" ]
+       ]
+}
index 3fef2cc..e8be528 100644 (file)
@@ -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 (file)
index 138045c..0000000
+++ /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;
-};