npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@paakways/ghananlp-node

v0.0.3

Published

A simple GhanaNLP API wrapper written in Typescript

Downloads

234

Readme

ghananlp-node

Simple Typescript wrapper for the GhanaNLP Translation API. Allows you to effortlessly translate text between supported languages and retrieve a list of available language pairs.

Table of Contents

Installation

Install the package via npm:

npm install @paakways/ghananlp-node

If you are using TypeScript, make sure to have axios types as a development dependency:

npm install --save-dev @types/axios

Getting Started

  1. Import the library into your Project

    import {GhanaNLP} from '@paakways/ghananlp-node';
  2. Initialize the library with your API Key and version

    To use the library, you will need to get an API key from the GhanaNLP APIs website.

    const api = new GhanaNLP('YOUR_API_KEY', 'v1');

Usage

Translate Text

To translate text from one language to another, use the translate method. You need to specify the input text and the language pair code (in the format from-to, e.g., en-tw for English to Twi).

    const translationRequest = { in: 'Hello World', lang: 'en-tw' };
    try {
        const response = await api.translate(translationRequest)
        console.log('Translated text:', response.translatedText);
    }
    catch(error) {
        console.error('Translation error:', error.message);
    }

Get Supported Languages

You can retrieve a list of all supported languages with their language codes:

    try {
        const languages = await api.getLanguages()
        console.log('Supported languages:', languages);
    }
    catch(error) {
        console.error('Error fetching languages:', error.message);
    }

Error Handling

The library provides error handling to help diagnose issues with the API requests. If an error occurs, it will throw a message detailing the type and description of the error.

Example of catching an error:

    try {
        const response = await api.translate({ in: 'Hello', lang: 'invalid-code' })
    }
    catch(error) {
        console.error('Error:', error.message); // Outputs detailed error message
    }

API Reference

translate(request: TranslationRequest): Promise<TranslationResponse>

Translates the given input text from one language to another.

  • Parameters:

    • request: An object containing:
      • in: The input text to be translated (max 1000 characters).
      • lang: Language pair code in the format from-to (e.g., en-tw).
  • Returns: A promise that resolves to the translated text.

getLanguages(): Promise<Language[]>

Retrieves the list of all supported languages.

  • Returns: A promise that resolves to an array of language objects, each containing:
    • code: The language code (e.g., en for English).
    • name: The full language name (e.g., English).

Coming Soon

  • TTS/STT API integration

Contributing

Contributions are welcome! If you find any bugs or have any feature requests, please open an issue or submit a pull request.

  1. Fork the repository.
  2. Create a new branch.
  3. Make your changes and commit them.
  4. Push your changes to the branch.
  5. Create a pull request.

License

This project is licensed under the MIT License.