Pig Latin

Translate your text into Pig Latin by adding an ‘ay’ syllable to the end of each word, with special rules for vowels and consonant clusters.

Face with waiting expression Nothing to see yet!

Loading takeymakey...
TakeyMakey code
Want this tool to do something else? Edit the code below and make it do whatever you want.
export const make = (text) =>
  text
    .split(/\b/g)
    .map((token) => {
      if (!/[a-z]/i.test(token)) return token

      // Is this a standard case, or is there a leading vowel?
      let [front, back] = /^([aeiou]|[^aeiouy]+$)/i.test(token)
        ? [token, "yay"]
        : [token.match(/[aeiouy].*$/i)[0], token.match(/[^aeiouy]+/i)[0] + "ay"]

      // Flip capitalisation
      if (back[0] !== back[0].toLowerCase()) {
        back = back[0].toLowerCase() + back.slice(1)
        front = front[0].toUpperCase() + front.slice(1)
      }

      // Don't double "y" in the suffix
      if (back[0] === "y" && front[front.length - 1] === "y") {
        back = back.slice(1)
      }

      return front + back
    })
    .join("")