nigeria-translator-browser
Version:
A lightweight and developer-friendly Node.js + TypeScript package for translating between English and major Nigerian languages — Igbo, Yoruba, and Hausa. Provides simple bidirectional translation functions (English ↔ Igbo, Yoruba, Hausa). Created with lov
21 lines (16 loc) • 794 B
text/typescript
import translate from "translate";
// Use MyMemory free engine
translate.engine = "google";
translate.key = undefined;
// Generic translate function
export async function translateText(text: string, to: string, from = "en") {
return await translate(text, { from, to });
}
// English → Nigerian
export const englishToIgbo = (text: string) => translateText(text, "ig");
export const englishToYoruba = (text: string) => translateText(text, "yo");
export const englishToHausa = (text: string) => translateText(text, "ha");
// Nigerian → English
export const igboToEnglish = (text: string) => translateText(text, "en", "ig");
export const yorubaToEnglish = (text: string) => translateText(text, "en", "yo");
export const hausaToEnglish = (text: string) => translateText(text, "en", "ha");