English to Pig Latin Translator (Python)

Encryption : The process of converting sensitive information into a code to protect it.

Encryption is one of the most important processes in most systems these days. Keeping data and personal information safe from crackers is of utmost importance and therefore encrypting sensitive data is mandatory. Encryption processes these days are highly advanced but one of the simplest and most well-known forms of encryption is Pig-Latin

Pig Latin is a simple spoken code that can keep your secrets safe from others. To anyone who doesn't know Pig Latin, the words sound funny but will make complete sense to everyone who understands Pig Latin. A simple Pig Latin translator in Python will be helpful when you need to convert any English word to Pig Latin in seconds, so your secrets remain safe. 

Rules of Pig Latin: 

The rules of Pig Latin are as follows: 

  • If the word to convert starts with a vowel: Just add '-yay' to the end of the word. Ex. Ant gets converted to Antyay.
  • If the word starts with a consonant or a group of consonants: The cluster of consonants are moved to the end of the word and '-ay' is added in the end. Ex. code gets converted to odecay. 
  • If the word starts with y: y is treated as a consonant. Ex. yes gets converted to esyay
  • If the word has y in any position other than the start: y is treated as a vowel. Ex. Python gets converted to ythonpay
Keeping these rules in mind, we can develop a simple code. 

We can start by just checking the first letter. If it is a vowel, case 1 is applied and the code can give us the output. If it is a consonant, we have to play around a little. 

What we can do is create a temporary list to store all the consonants till the first vowel or 'y' in the word. Once we do that, we can remove all the starting consonants from the original word and add it to the end using our temporary list. Finally to cap it off, we can add '-ay' at the end to get the final output. 

If you look at the code now: Pig Latin Translator

#Pig-Latin Translator

word = input('Enter a word: ')

word_split = [letter.lower() for letter in word]

vowel_list = ['a','e','i','o','u']

#Case 1 - Word begins with vowel:

if word[0].lower() in vowel_list:
    translation = word + 'yay'

#Case 2 - Word begins with consonant or consonant cluster

else:
    temporary_list = []
    
    for i in range(0,len(word_split)):
        if word_split[i].lower() not in vowel_list and word_split[i].lower() != 'y':
            temporary_list.append(word_split[i].lower())
        else:
            break

    for j in temporary_list:
        if j in word_split:
            word_split.remove(j)
    
    word_split.extend(temporary_list)

    translation = ''.join(word_split) + 'ay'


print(translation)

The output would look something like this: 

When the word starts with a vowel:
Enter a word: Ant
Antyay
>>> 

or 

When the word starts with a consonant or consonant cluster (y is treated as a vowel):
Enter a word: Python
ythonpay
>>> 

Possible Edits: 
  • Make a Pig-Latin translator for paragraphs. Create a function to make the work simpler and use the word.split() function to break down the paragraph into words.
  • Try to build a Pig-Latin to English converter. Some small edits to the same code will do the trick. 

If you have any comments or queries, please feel free to use the comment section to let me know and I will try to get back with the answer as soon as I can. Until then, oodbyegay 

Do follow ThePygrammer to be updated every time a new post comes out. Just click the blue button in the menu to follow. 

If you want to explore more similar programs:

Comments