Esto perpetue May you last forever

–Latin

I’ve seen a few places on the net requesting Pig Latin translators and decided to write my own.  I have created for you in PHP a Pig Latin translator.  It’s rather simple it uses the three known rules which are the following:

  • For words that begin with consonants, move the leading consonant(s) to the end of the word and add “ay.” Thus, “ball” becomes “all-bay”; “button” becomes “utton-bay”; “star” becomes “ar-stay”; “three” becomes “ee-thray”;
  • for words beginning with “qu,” move the “qu” to the end of the word and add ay. Thus “question” becomes “estion-quay”; and
  • for words that begin with vowels, simply add “way” to the end of the word. Thus, “a” becomes “a-way”; “at” becomes “at-way”; “ermine” becomes “ermine-way.” This rule tends to get varied a lot, with some variants using instead “h” (thus, “at” becomes “at-hay”), or some just using the bare syllable “ay” (”at” becomes “at-ay”).

In my pig translator I’ve included handling for the three types of vowel rules, as well as some capitalization handling as well as limited punctuation handling.  I wrote it quickly and thus the new category ‘dirty scripts’ of which this PHP Pig-Latin translator will be the first entry. “Dirty Scripts” is were I plan to place scripts that aren’t the old archived unstable, but the new unstable code. :) Anyway without further ado,

$word){

	$first_char = substr($word,0,1);
	$endLetter = substr($word,strlen($word)-1);
	$punctuation = false;
	if(isPunctuationMark($endLetter)){
		$word = substr($word,0,strlen($word)-1);
		$punctuation = true;
	}
	if(isQu($word)){
		$words[$key] = substr($word,2).'-'.substr($word,0,2);
	}elseif(isVowel($first_char)){
		if($vowel_rule == 1){
			$words[$key] = $word.'-way';
		}elseif($vowel_rule==2){
			$words[$key] = $word.'-hay';
		}else{
			$words[$key] = $word.'-ay';
		}
	}else{
		$words[$key] = substr($word,1).'-'.$first_char.'ay';
	}
	//case fixing
	if(ereg('[A-Z]',$word) !== false){
		$words[$key] = ucfirst(strtolower($words[$key]));
	}
	if($punctuation){
		$translated_text .= $words[$key].$endLetter.' ';
	}else{
		$translated_text .= $words[$key].' ';
	}
}

function isVowel($letter){
	$letter = strtolower($letter);
	if(in_array($letter,array('a','e','i','o','u'))){
		return true;
	}else return false;
	return false;
}
function isQu($word){
	$word = strtolower($word);
	if(substr($word,0,2) == 'qu'){
		return true;
	}else return false;
	return false;
}
function isPunctuationMark($endLetter){
	if(in_array($endLetter,array(';',',','.','?',':'))){
		return true;
	}else return false;
	return false;
}

?>



Enter in your text to be translated to pig latin.

Choose your vowel rule. Example at become at-way or at-hay or at-ay. -way -hay -ay

And if you like my script above let me know, there is a share your thoughts link at the top.