User:AlefZet/crh/LanguageCrh latn.php

    From Wikimedia Incubator

    /*

    */
    <?php
    /** Crimean Tatar (Qırımtatarca)
      *
      *
      * @package MediaWiki
      * @subpackage Language
      */
    
    
    class LanguageCrh_latn extends Language {
    
     	# Convert from the nominative form of a noun to some other case
    	# Invoked with {{GRAMMAR:case|word}}
    	/**
    	 * Cases: genitive, dative, accusative, locative, ablative + possessive forms
    	 */
    	function convertGrammar( $word, $case ) {
    		global $wgGrammarForms;
    		if ( isset( $wgGrammarForms['crh'][$case][$word] ) ) {
    			return $wgGrammarForms['crh'][$case][$word];
    		}
    		// Set up some constants...
        // Vowels in last syllable
    		$frontVowels = array( "e", "ö", "ü", "i" );
    		$backVowels = array( "a", "o", "u", "ı", "â", "q" );
        $allVowels = array( "e", "ö", "ü", "i", "a", "o", "u", "ı", "â" );
        // Preceding letters
    		$preVowels = $allVowels;
    		$preVoiceds = array( "b", "c", "d", "g", "ğ", "j", "l", "m", "n", "ñ", "r", "v", "y", "z" );
    		$preVoicelesses = array( "ç", "f", "h", "k", "p", "q", "s", "ş", "t" );
        $preSonorants = array( "a", "â", "b", "c", "d", "e", "g", "ğ", "i", "ı", "j", "l", "m", "n", "ñ", "o", "ö", "r", "u", "ü", "v", "y", "z" );
        $preChars = array( "a", "â", "b", "c", "ç", "d", "e", "f", "g", "ğ", "h", "i", "ı", "j", "k", "l", "m", "n", "ñ", "o", "ö", "p", "q", "r", "s", "ş", "t", "u", "ü", "v", "y", "z" );
    
        // Possessives
        $firsts = array( "m", "ñ" ); // 1st singular, 2nd unformal
        $seconds = array( "z", "r");     // 1st plural, 2nd formal
        $thirds = array( "ı", "i" ); // 3rd
    
    		// Put the word in a form we can play with since we're using UTF-8
        $ar = array();
        $ar = preg_split('//u', $word, -1, PREG_SPLIT_NO_EMPTY);
    		$wordEnding = $ar[count( $ar ) - 1]; //Here's the last letter in the word
    		$wordReversed = array_reverse( $ar ); //Here's an array with the order of the letters in the word reversed so we can find a match quicker *shrug*
    
    		// Find the last vowel in the word
    		$wordLastVowel = NULL;
    		foreach ( $wordReversed as $xvalue ) {
    			foreach ( $allVowels as $yvalue ) {
    				if ( strcmp( $xvalue, $yvalue ) == 0 ) {
    					$wordLastVowel = $xvalue;
    					break;
    				} else {
    					continue;
    				}
    			}
    			if ( $wordLastVowel !== NULL ) {
    				break;
    			} else {
    				continue;
    			}
    		}
    
    		// Now convert the word
    		switch ( $case ) {
    			case "dc1":
    			case "genitive":
    			case "dc11":
    			case "possessive genitive":
    				if ( in_array( $wordEnding, $preChars ) ) {
    					if ( in_array( $wordLastVowel, $frontVowels ) ) {
    						$word = implode( "", $ar ) . "niñ";
    					} elseif ( in_array( $wordLastVowel, $backVowels ) ) {
    						$word = implode( "", $ar ) . "nıñ";
    					}
    				} 
    				break;
    			case "dc2":
    			case "dative":
    				if ( in_array( $wordEnding, $preVoicelesses ) ) {
    					if ( in_array( $wordLastVowel, $frontVowels ) ) {
    						$word = implode( "", $ar ) . "ke";
    					} elseif ( in_array( $wordLastVowel, $backVowels ) ) {
    						$word = implode( "", $ar ) . "qa";
    					}
    				} elseif ( in_array( $wordEnding, $preSonorants ) ) {
    					if ( in_array( $wordLastVowel, $frontVowels ) ) {
    						$word = implode( "", $ar ) . "ge";
    					} elseif ( in_array( $wordLastVowel, $backVowels ) ) {
    						$word = implode( "", $ar ) . "ğa";
    					}
            }
    				break;
    			case "dc21":
    			case "possessive dative":
    				if ( in_array( $wordEnding, $firsts ) ) {
    					if ( in_array( $wordLastVowel, $frontVowels ) ) {
    						$word = implode( "", $ar ) . "e";
    					} elseif ( in_array( $wordLastVowel, $backVowels ) ) {
    						$word = implode( "", $ar ) . "a";
    					}
    				} elseif ( in_array( $wordEnding, $seconds ) ) {
    					if ( in_array( $wordLastVowel, $frontVowels ) ) {
    						$word = implode( "", $ar ) . "ge";
    					} elseif ( in_array( $wordLastVowel, $backVowels ) ) {
    						$word = implode( "", $ar ) . "ğa";
    					}
        		} elseif ( in_array( $wordEnding, $thirds ) ) {
    				  if ( in_array( $wordLastVowel, $frontVowels ) ) {
    						$word = implode( "", $ar ) . "ne";
    					} elseif ( in_array( $wordLastVowel, $backVowels ) ) {
    						$word = implode( "", $ar ) . "na";
    					}
    				}
    				break;
    			case "dc3":
    			case "accusative":
    				if ( in_array( $wordEnding, $preChars ) ) {
    					if ( in_array($wordLastVowel, $frontVowels ) ) {
    						$word = implode( "", $ar ) . "ni";
    					} elseif ( in_array( $wordLastVowel, $backVowels ) ) {
    						$word = implode( "", $ar ) . "nı";
    					}
    				}
    				break;
    			case "dc31":
    			case "possessive accusative":
    				if ( in_array( $wordEnding, $firsts ) || in_array( $wordEnding, $seconds ) || in_array( $wordEnding, $thirds ) ) {
    					if ( in_array( $wordLastVowel, $frontVowels ) ) {
    						$word = implode( "", $ar ) . "ni";
    					} elseif ( in_array( $wordLastVowel, $backVowels ) ) {
    						$word = implode( "", $ar ) . "nı";
    					}
    				}
    				break;
    			case "dc4":
    			case "locative":
    				if ( in_array( $wordEnding, $preVoicelesses ) ) {
    					if ( in_array( $wordLastVowel, $frontVowels ) ) {
    						$word = implode( "", $ar ) . "te";
    					} elseif ( in_array( $wordLastVowel, $backVowels ) ) {
    						$word = implode( "", $ar ) . "ta";
    					}
    				} elseif ( in_array( $wordEnding, $preSonorants ) ) {
    					if ( in_array( $wordLastVowel, $frontVowels) ) {
    						$word = implode( "", $ar ) . "de";
    					} elseif ( in_array( $wordLastVowel, $backVowels ) ) {
    						$word = implode( "",$ar ) . "da";
    					}
    				}
    				break;
    			case "dc41":
    			case "possessive locative":
    				if ( in_array( $wordEnding, $firsts ) || in_array( $wordEnding, $seconds ) ) {
    					if ( in_array( $wordLastVowel, $frontVowels ) ) {
    						$word = implode( "", $ar ) . "de";
    					} elseif ( in_array( $wordLastVowel, $backVowels ) ) {
    						$word = implode( "", $ar ) . "da";
    					}
    				} elseif ( in_array( $wordEnding, $thirds ) ) {
    					if ( in_array( $wordLastVowel, $frontVowels) ) {
    						$word = implode( "", $ar ) . "nde";
    					} elseif ( in_array( $wordLastVowel, $backVowels ) ) {
    						$word = implode( "",$ar ) . "nda";
    					}
    				}
    				break;
    			case "dc5":
    			case "ablative":
    				if ( in_array( $wordEnding, $preVoicelesses ) ) {
    					if ( in_array( $wordLastVowel, $frontVowels ) ) {
    						$word = implode( "", $ar ) . "ten";
    					} elseif ( in_array( $wordLastVowel, $backVowels ) ) {
    						$word = implode( "", $ar ) . "tan";
    					}
    				} elseif ( in_array($wordEnding, $preSonorants )  ) {
    					if ( in_array( $wordLastVowel, $frontVowels ) ) {
    						$word = implode( "", $ar ) . "den";
    					} elseif ( in_array( $wordLastVowel, $backVowels ) ) {
    						$word = implode( "", $ar ) . "dan";
    					}
    				}
    				break;
    			case "dc51":
    			case "possessive ablative":
    				if ( in_array( $wordEnding, $firsts ) || in_array( $wordEnding, $seconds ) ) {
    					if ( in_array( $wordLastVowel, $frontVowels ) ) {
    						$word = implode( "", $ar ) . "den";
    					} elseif ( in_array( $wordLastVowel, $backVowels ) ) {
    						$word = implode( "", $ar ) . "dan";
    					}
    				} elseif ( in_array($wordEnding, $thirds ) ) {
    					if ( in_array( $wordLastVowel, $frontVowels ) ) {
    						$word = implode( "", $ar ) . "nden";
    					} elseif ( in_array( $wordLastVowel, $backVowels ) ) {
    						$word = implode( "", $ar ) . "ndan";
    					}
    				}
    				break;
    			case "dc6":
    			case "comitative":
    				if ( in_array( $wordEnding, $preChars ) ) {
    						$word = implode( "", $ar ) . "nen";
    				} 
    				break;
    			case "dc61":
    			case "possessive comitative":
    				if ( in_array( $wordEnding, $firsts ) || in_array( $wordEnding, $seconds ) || in_array( $wordEnding, $thirds ) ) {
    						$word = implode( "", $ar ) . "nen";
    				} 
    				break;
    			default: #dc0 #nominative
    		}
    		return $word;
    	}
    
    	function ucfirst ( $string ) {
    		if ( $string[0] == 'i' ) {
    			return 'İ' . substr( $string, 1 );
    		} else {
    			return parent::ucfirst( $string );
    		}
    	}
    
    	/**
    	 * Avoid grouping whole numbers between 0 to 9999
    	 */
    	function commafy( $_ ) {
    		if ( !preg_match( '/^\d{1,4}$/', $_ ) ) {
    			return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev($_) ) );
    		} else {
    			return $_;
    		}
    	}
    }
    
    ?>
    /*
    

    */