English To 'Pig Latin'

Yesterday, I was doing some research about 'Latin' and 'Roman Civilization' and as I was scouring the internet, I stumbled upon this slang (or 'Backslang') called 'Pig Latin', which is also a 'English Language Game'. Following are the rules to translate a 'English' word into 'Pig Latin':

1) For words that begin with 'consonant' sounds, move the initial consonant or consonant cluster to the end of the word and add "ay."

Ex: English: Zeitgeist ------ Pig Latin: eitgeistzay

2) For words that begin with vowel sounds (including silent consonants), simply add the syllable "ay" to the end of the word.

Ex: Englsih: Algorithm ------ Pig Latin: Algorithmway

This is the basic stuff for 'Pig Latin'. If you wanna know more about this, you can fire a Google query and do some research. Also, I'm not covering much of 'silent consonants' stuff in this post.

Ok..I thought its pretty simple and wrote a basic 'Java' program to translate an 'English phrase' into 'Pig Latin'. This is a pretty basic 'Java' program tested with just a couple of test cases. And ofcourse, there are a lot of other things to be added, in order to make it a perfect translator. I'm just posting the 'Java' code that I wrote in a couple of minutes, outta my own interest. Here's the code:

import java.util.Scanner;

public class EnglishToPigLatinTranslator {
public static void main(String[] args) {
System.out.println("Enter The English Phrase To Be " 
+ "Translated Into 'Pig Latin' : ");
Scanner scanner = new Scanner(System.in);

String strEngPhrase = scanner.nextLine();

if(strEngPhrase != null && !strEngPhrase.equals("")) {
System.out.println("\nPig Latin Text : \n" + 
convertEnglishToPigLatin(strEnglishPhrase));
} else {
System.out.println("No Input Specified!");
}
}

public static String convertEnglishToPigLatin(String strEnglishPhrase) {
String strVowels = "aeiou";
String[] strTokens = strEnglishPhrase.split("[ ]");
StringBuffer sbPigLatinStuff = new StringBuffer();

for(int i=0;i<strTokens.length;i++) {
if(strVowels.indexOf(strTokens[i].charAt(0)) >= 0) {
sbPigLatinStuff.append(strTokens[i] + "way ");
} else if((strTokens[i].indexOf("a") < 0) && 
(strTokens[i].indexOf("e") < 0) && 
(strTokens[i].indexOf("i") < 0) && 
(strTokens[i].indexOf("o") < 0) && 
(strTokens[i].indexOf("u") < 0)) {
sbPigLatinStuff.append(strTokens[i] + "ay ");          
} else {
for(int j=1;j<strTokens[i].length();j++) {
if(strVowels.indexOf(strTokens[i].charAt(j)) >= 0) {
sbPigLatinStuff.append(strTokens[i].substring(j) + 
strTokens[i].substring(0,j) + "ay ");
break;
}
}
}
}

return sbPigLatinStuff.toString();
}
}



The above code reads/takes 'English' phrase as input from the console and outputs a 'Pig Latin' phrase as output.

Example Input: She sells sea shells by the sea shore
Output: eShay ellssay easay ellsshay byay ethay easay oreshay

Also, the above code doesn't take care of special characters. If you want, you can customize that, accordingly. Here's an input phrase, which shows that:

Input: A skunk sat on a stump and thunk the stump stunk, but the stump thunk the skunk stunk.

Output: Aay unkskay atsay onway away umpstay andway unkthay ethay umpstay unk,stay utbay ethay umpstay unkthay ethay unkskay unk.stay

One more interesting thing is that, Google also offers its search in 'Pig Latin'. I used the link and searched using a set of keywords and found that this 'Pig Latin' search gives priority to 'Pig Latin' stuff only if you search in 'Pig Latin'. Otherwise, it is just the usual way of 'Googling'. I dont know if they cover all the cases, but here's the link:

Google Igpay Atinlay (Pig Latin)

2 comments:

  1. Thanks for the help with the pig latin code, I was struggling with how to find the spaces and then once a space is found jumping to the next word.

    ReplyDelete
  2. HOW I GOT MY LOAN (Lexieloancompany@yahoo.com)!!!

    My Name is Nicole Marie, I live in USA and life is worth living comfortably for me and my family now and i really have never seen goodness shown to me this much in my life, As i am a struggling mum with two kids and i have been going through a serious problem as my husband encountered a terrible accident last two weeks, and the doctors stated that he needs to undergo a delicate surgery for him to be able to walk again and i could not afford the bills for his surgery then i went to the bank for a loan and they turn me down stating that i have no credit card, from there i ran to my father and he was not able to help me, then when i was browsing through yahoo answers i came across a God fearing man (Mr Martinez Lexie) who provides loans at an affordable interest rate and i have been hearing about so many scams on the Internet mostly Africa, but at this my desperate situation, i had no choice than to give it an attempt due to the fact that the company is from United State of America, and surprisingly it was all like a dream, i received a loan of $82,000.00 USD and i payed for my husband surgery and thank GOD today he is ok and can walk, my family is happy and i said to myself that i will shout to the world the wonders this great and God fearing Man Mr Martinez Lexie did for me and my family; so if anyone is in genuine and serious need of a loan do contact this GOD fearing man via Email: ( Lexieloancompany@yahoo.com ) or through the Company website: http://lexieloans.bravesites.com OR text: +18168926958 thanks


    ReplyDelete

Note: Only a member of this blog may post a comment.