import re

VOWELS = ('a', 'e', 'i', 'o', 'u')
VOWEL_SND_SUFFIX = "yay"
CONSONANT_SND_SUFFIX = "ay"

def translate_text(input_text):
  text_translation = []

  for match in re.finditer("(?P<not_word>\W+)|(?P<word>[\w']+)", input_text):
    if match.group("word") == None:
      text_translation.append(match.group("not_word"))
    else:
      translated_word = translate_word(match.group("word"))
      translated_word = proper_case(match.group("word"), translated_word)
      text_translation.append(translated_word)
  return "".join(text_translation)

def translate_word(word):
  assert(len(word) > 0)

  word = word.lower()

  if word[0] in VOWELS:
    return word + VOWEL_SND_SUFFIX
  else:
    for idx, char in enumerate(word):
      if char in VOWELS:
        return word[idx:] + word[:idx] + CONSONANT_SND_SUFFIX
    return word + CONSONANT_SND_SUFFIX

def proper_case(word, translated_word):
  if word.title() == word:
    return translated_word.title()

  return translated_word
