There are various ways to solve Pig Latin. One way is to use regular expressions (also known as regex) for processing the input. Solutions using regex can be very succinct, but require familiarity with regex patterns, which are like another language. Another way is to use a series of conditional statements to test which of several rules the input matches. Another approach is to use sets for look-up and then slice the input to return the correct value.
At the time of writing only four rules need to be handled, but if they have similar output, they don't need to be handled completely separately.
VOWELS = {"a", "e", "i", "o", "u"}
VOWELS_Y = {"a", "e", "i", "o", "u", "y"}
SPECIALS = {"xr", "yt"}
def translate(text):
piggyfied = []
for word in text.split():
if word[0] in VOWELS or word[0:2] in SPECIALS:
piggyfied.append(word + "ay")
continue
for pos in range(1, len(word)):
if word[pos] in VOWELS_Y:
pos += 1 if word[pos] == 'u' and word[pos - 1] == "q" else 0
piggyfied.append(word[pos:] + word[:pos] + "ay")
break
return " ".join(piggyfied)
For more information, check the sets and slices approach.