nigeria-translator
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) powered by the Bi
233 lines (169 loc) β’ 5.86 kB
Markdown
# π³π¬ nigeria-translator




A lightweight, developer-friendly TypeScript package for translating between English and major Nigerian languages (Igbo, Yoruba, and Hausa).
Perfect for chatbots, APIs, learning apps, and automation workflows.
**Created with β€οΈ by [Achu-ulim Agbama](https://github.com/Achufam24)**
## β¨ Features
- π **Bidirectional translation** β English β Igbo/Yoruba/Hausa
- π **Full TypeScript support** with type definitions
- β‘ **Zero configuration** β works out of the box
- πͺΆ **Lightweight** with minimal dependencies
- π **Promise-based async API** for modern workflows
## π¦ Installation
```bash
npm install nigeria-translator
```
```bash
# Or with yarn
yarn add nigeria-translator
```
```bash
# Or with pnpm
pnpm add nigeria-translator
```
## π Quick Start
```javascript
const { englishToIgbo, igboToEnglish } = require('nigeria-translator');
async function translate() {
const igbo = await englishToIgbo('Hello');
console.log(igbo); // Output: Ndewo
const english = await igboToEnglish('Ndewo');
console.log(english); // Output: Hello
}
translate();
```
## π Usage
### JavaScript (CommonJS)
```javascript
const {
englishToIgbo,
englishToYoruba,
englishToHausa,
igboToEnglish,
yorubaToEnglish,
hausaToEnglish
} = require('nigeria-translator');
async function examples() {
// English to Nigerian languages
console.log(await englishToIgbo('come')); // β bia
console.log(await englishToYoruba('how are you')); // β bawo ni
console.log(await englishToHausa('food')); // β abinci
// Nigerian languages to English
console.log(await igboToEnglish('bia')); // β come
console.log(await yorubaToEnglish('bawo ni')); // β how are you
console.log(await hausaToEnglish('abinci')); // β food
}
examples();
```
### TypeScript (ES Modules)
```typescript
import {
englishToIgbo,
englishToYoruba,
englishToHausa,
igboToEnglish,
yorubaToEnglish,
hausaToEnglish
} from 'nigeria-translator';
async function main(): Promise<void> {
const igbo = await englishToIgbo('friend');
const yoruba = await englishToYoruba('house');
const hausa = await englishToHausa('water');
console.log(igbo); // β enyi
console.log(yoruba); // β ile
console.log(hausa); // β ruwa
const translation = await igboToEnglish('anyα»');
console.log(translation); // β we/us
}
main();
```
### Express.js API
```javascript
import express from 'express';
import { englishToYoruba } from 'nigeria-translator';
const app = express();
app.get('/translate', async (req, res) => {
try {
const { text } = req.query;
const translated = await englishToYoruba(text);
res.json({ original: text, translated });
} catch (error) {
res.status(500).json({ error: 'Translation failed' });
}
});
app.listen(3000, () => {
console.log('π Translation API running on http://localhost:3000');
});
```
### NestJS Service
```typescript
// translate.service.ts
import { Injectable } from '@nestjs/common';
import {
englishToIgbo,
englishToYoruba,
englishToHausa
} from 'nigeria-translator';
@Injectable()
export class TranslateService {
async translateToIgbo(text: string): Promise<string> {
return englishToIgbo(text);
}
async translateToYoruba(text: string): Promise<string> {
return englishToYoruba(text);
}
async translateToHausa(text: string): Promise<string> {
return englishToHausa(text);
}
}
```
## π API Reference
### English β Nigerian Languages
| Function | Description | Returns |
|----------|-------------|---------|
| `englishToIgbo(text: string)` | Translate English to Igbo | `Promise<string>` |
| `englishToYoruba(text: string)` | Translate English to Yoruba | `Promise<string>` |
| `englishToHausa(text: string)` | Translate English to Hausa | `Promise<string>` |
### Nigerian Languages β English
| Function | Description | Returns |
|----------|-------------|---------|
| `igboToEnglish(text: string)` | Translate Igbo to English | `Promise<string>` |
| `yorubaToEnglish(text: string)` | Translate Yoruba to English | `Promise<string>` |
| `hausaToEnglish(text: string)` | Translate Hausa to English | `Promise<string>` |
**Note:** All functions are async and return Promises. Use `await` or `.then()` to handle the results.
## π οΈ Use Cases
- **Chatbots** β WhatsApp, Telegram, Discord bots with Nigerian language support
- **APIs** β Add translation endpoints to your REST or GraphQL APIs
- **Learning Apps** β Build language learning tools for Nigerian languages
- **Content Localization** β Translate UI strings, notifications, and content
- **AI Assistants** β Enhance voice and text assistants with local language support
## π€ Contributing
Contributions are welcome! If you'd like to improve this package:
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## π¨βπ» Author
**Achu-ulim Agbama**
Software Engineer @ Nugitech
Made with passion for Nigerian culture and accessibility π³π¬
- GitHub: https://github.com/Achufam24
- Twitter: https://x.com/agbama_achu
## π License
[ISC License](LICENSE) β Free for personal and commercial use.
## π Show Your Support
If this package helped you, please give it a β on [GitHub](https://github.com/Achufam24/nigeria-translator)!