Translates English text to Pig Latin, with proper handling of capitalization, punctuation, and hyphenated phrases.
Igpay Atinlay orfay ouryay AvaScriptjay/YpeScript-tay ojectpray. Atwhay ouldcay ebay etterbay? (Exceptyay aconbay, ofyay oursecay.)
Other Pig-Latin translators exist, but none of them worked as well as I wanted, so I created this one. Highlights:
It preserves all punctuation and whitespace perfectly, including tabs and line breaks.
It splits input words on whitespace, slashes, underscores, and dashes (not just whitespace), so
perfectly-fried bacon and/or ham is _so_tasty_translates to
erfectlypay-iedfray aconbay andyay/oryay amhay isyay _osay_astytay_.
It handles capitalization and all-caps nicely, so
Bacon is AWESOME!translates to
Aconbay isyay AWESOMEYAY!.
It knows that
Yis a consonant at the beginning of a word, and a vowel otherwise, so
It hyphenates when needed to prevent hard-to-read repeated consonants from appearing at the end of translated words, so
It removes apostrophes in possessives and contractions to avoid mangling them, while still preserving leading and trailing apostrophes, e.g.
A pig's ears aren't tasty, don't eat 'emtranslates to
Ayay igspay earsyay arentyay astytay, ontday eatyay 'emyay- no awkward
It doesn't mangle words for which there is no rational Pig Latin translation, such as
v1.0- they're passed though as-is.
It allows words to be added to an exclusions list; excluded words will be passed through without translation.
It has no dependencies, so it won't bloat up your bundle.
It comes with TypeScript bindings.
yarn add pig-latinizer yarn remove pig-latinizer
Usage in TypeScript
import PigLatin from "pig-latinizer" const pigLatin: PigLatin = new PigLatin() pigLatin.exclusions.push("woot") const translated: string = pigLatin.translate("Bacon, woot!") // Aconbay, woot!
Usage in Node
const PigLatin = require("pig-latinizer").default const pigLatin = new PigLatin() pigLatin.exclusions.push("woot") const translated = pigLatin.translate("Bacon, woot!") // Aconbay, woot!