LanguageKsh.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. /**
  3. * Ripuarian (Ripoarėsh) 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. * @author Purodha Blissenbach
  22. * @ingroup Language
  23. */
  24. /**
  25. * Ripuarian (Ripoarėsh)
  26. *
  27. * @ingroup Language
  28. */
  29. class LanguageKsh extends Language {
  30. private static $familygender = [
  31. // Do not add male wiki families, since that's the default.
  32. // No need add neuter wikis having names ending in -wiki.
  33. 'wikipedia' => 'f',
  34. 'wikiversity' => 'f',
  35. 'wiktionary' => 'n',
  36. 'wikibooks' => 'n',
  37. 'wikiquote' => 'n',
  38. 'wikisource' => 'n',
  39. 'wikitravel' => 'n',
  40. 'wikia' => 'f',
  41. 'translatewiki.net' => 'n',
  42. ];
  43. /**
  44. * Convert from the nominative form of a noun to other cases.
  45. * Invoked with {{GRAMMAR:case|word}} inside messages.
  46. *
  47. * case is a sequence of words, each of which is case insensitive.
  48. * Between words, there must be at least one space character.
  49. * Only the 1st character of each word is considered.
  50. * Word order is irrelevant.
  51. *
  52. * Possible values specifying the grammatical case are:
  53. * 1, Nominative
  54. * 2, Genitive
  55. * 3, Dative
  56. * 4, Accusative, -omitted-
  57. *
  58. * Possible values specifying the article type are:
  59. * Betoont focussed or stressed article
  60. * -omitted- unstressed or unfocussed article
  61. *
  62. * Possible values for the type of genitive are:
  63. * Sing, Iehr prepositioned genitive = possessive dative
  64. * Vun, Fon, -omitted- postpositioned genitive = preposition "vun" with dative
  65. *
  66. * Values of case overrides & prepositions, in the order of preceedence:
  67. * Sing, Iehr possessive dative = prepositioned genitive
  68. * Vun, Fon preposition "vun" with dative = postpositioned genitive
  69. * En, em preposition "en" with dative
  70. *
  71. * Values for object gender specifiers of the possessive dative, or
  72. * prepositioned genitive, evaluated with "Sing, Iehr" of above only:
  73. * Male a singular male object follows
  74. * -omitted- a non-male or plural object follows
  75. *
  76. * We currently handle definite articles of the singular only.
  77. * There is a full set of test cases at:
  78. * http://translatewiki.net/wiki/Portal:Ksh#GRAMMAR_Pr%C3%B6%C3%B6fe
  79. * Contents of the leftmost table column can be copied and pasted as
  80. * "case" values.
  81. *
  82. * @param string $word
  83. * @param string $case
  84. *
  85. * @return string
  86. */
  87. function convertGrammar( $word, $case ) {
  88. $lord = strtolower( $word );
  89. $gender = 'm'; // Nuutnaarel // default
  90. if ( preg_match( '/wiki$/', $lord ) ) {
  91. $gender = 'n'; // Dat xyz-wiki
  92. }
  93. if ( isset( self::$familygender[$lord] ) ) {
  94. $gender = self::$familygender[$lord];
  95. }
  96. $case = ' ' . strtolower( $case );
  97. if ( preg_match( '/ [is]/', $case ) ) {
  98. # däm WikiMaatplaz singe, dä Wikipeedija iere, däm Wikiwööterbooch singe
  99. # dem/em WikiMaatplaz singe, de Wikipeedija iere, dem/em Wikiwööterbooch singe
  100. # däm WikiMaatplaz sing, dä Wikipeedija ier, däm Wikiwööterbooch sing
  101. # dem/em WikiMaatplaz sing, de Wikipeedija ier, dem/em Wikiwööterbooch sing
  102. $word = ( preg_match( '/ b/', $case )
  103. ? ( $gender == 'f' ? 'dä' : 'däm' )
  104. : ( $gender == 'f' ? 'de' : 'dem' )
  105. ) . ' ' . $word . ' ' .
  106. ( $gender == 'f' ? 'ier' : 'sing' ) .
  107. ( preg_match( '/ m/', $case ) ? 'e' : ''
  108. );
  109. } elseif ( preg_match( '/ e/', $case ) ) {
  110. # en dämm WikiMaatPlaz, en dä Wikipeedija, en dämm Wikiwööterbooch
  111. # em WikiMaatplaz, en de Wikipeedija, em Wikiwööterbooch
  112. if ( preg_match( '/ b/', $case ) ) {
  113. $word = 'en ' . ( $gender == 'f' ? 'dä' : 'däm' ) . ' ' . $word;
  114. } else {
  115. $word = ( $gender == 'f' ? 'en de' : 'em' ) . ' ' . $word;
  116. }
  117. } elseif ( preg_match( '/ [fv]/', $case ) || preg_match( '/ [2jg]/', $case ) ) {
  118. # vun däm WikiMaatplaz, vun dä Wikipeedija, vun däm Wikiwööterbooch
  119. # vum WikiMaatplaz, vun de Wikipeedija, vum Wikiwööterbooch
  120. if ( preg_match( '/ b/', $case ) ) {
  121. $word = 'vun ' . ( $gender == 'f' ? 'dä' : 'däm' ) . ' ' . $word;
  122. } else {
  123. $word = ( $gender == 'f' ? 'vun de' : 'vum' ) . ' ' . $word;
  124. }
  125. } elseif ( preg_match( '/ [3d]/', $case ) ) {
  126. # dämm WikiMaatPlaz, dä Wikipeedija, dämm Wikiwööterbooch
  127. # dem/em WikiMaatplaz, de Wikipeedija, dem/em Wikiwööterbooch
  128. if ( preg_match( '/ b/', $case ) ) {
  129. $word = ( $gender == 'f' ? 'dää' : 'dämm' ) . ' ' . $word;
  130. } else {
  131. $word = ( $gender == 'f' ? 'de' : 'dem' ) . ' ' . $word;
  132. }
  133. } else {
  134. # dä WikiMaatPlaz, di Wikipeedija, dat Wikiwööterbooch
  135. # der WikiMaatplaz, de Wikipeedija, et Wikiwööterbooch
  136. if ( preg_match( '/ b/', $case ) ) {
  137. switch ( $gender ) {
  138. case 'm':
  139. $lord = 'dä';
  140. break;
  141. case 'f':
  142. $lord = 'di';
  143. break;
  144. default:
  145. $lord = 'dat';
  146. }
  147. } else {
  148. switch ( $gender ) {
  149. case 'm':
  150. $lord = 'der';
  151. break;
  152. case 'f':
  153. $lord = 'de';
  154. break;
  155. default:
  156. $lord = 'et';
  157. }
  158. }
  159. $word = $lord . ' ' . $word;
  160. }
  161. return $word;
  162. }
  163. /**
  164. * Handle cases of (1, other, 0) or (1, other)
  165. *
  166. * @param int $count
  167. * @param array $forms
  168. *
  169. * @return string
  170. */
  171. function convertPlural( $count, $forms ) {
  172. $forms = $this->handleExplicitPluralForms( $count, $forms );
  173. if ( is_string( $forms ) ) {
  174. return $forms;
  175. }
  176. if ( !count( $forms ) ) {
  177. return '';
  178. }
  179. $forms = $this->preConvertPlural( $forms, 3 );
  180. if ( $count == 1 ) {
  181. return $forms[0];
  182. } elseif ( $count == 0 ) {
  183. return $forms[2];
  184. } else {
  185. return $forms[1];
  186. }
  187. }
  188. }