Everything You Need to Know About the GhanaNLP Translation API

Photo by Ato Aikins on Unsplash

Everything You Need to Know About the GhanaNLP Translation API

Welcome to GhanaNLP Translation API guide, Akwaaba

Cool, you made it! I assume you have already set up an account. If not, please check out the introductory blog to the GhanaNLP series and come back when you're up to speed.

Language diversity is a big part of Ghana’s culture. As we go digital, we need to bridge language gaps across dialects. Integrating API services into our platforms can better serve the Ghanaian community. This is one vision of Project JALI. The GhanaNLP Translation REST API translates text between some African languages and English.

In this blog post, we'll cover everything you need to know about setting up and using this API.

GhanaNLP Translation API v1

The GhanaNLP Translation API is an easy-to-use RESTful service that allows you to translate text from English to local Ghanaian languages such as Twi, Ga, Ewe, and more. This service is especially useful for developers building apps that require localization or translation for Ghanaian audiences.

Key Features

  • Supports multiple languages: Translations are available for languages like Twi (tw), Ga (gaa), Ewe (ee), Fante (fat), Dagbani (dag), Gurene (gur), Yoruba (yo), and more.

  • Simple JSON-based requests and responses: Communicate with the API using standard JSON payloads.

  • Easy integration: The REST API can be integrated with any application, whether it’s a website, mobile app, or desktop software.

How to Use the GhanaNLP Translation API

API Endpoint

The request URL you’ll use is:

https://translation-api.ghananlp.org/v1/translate

In simple terms, the request URL acts as a link between your code and the API service, allowing you to send and receive data.

The API Request Structure

To make a translation request, you’ll need to send a POST request with a JSON payload that includes two key pieces of information: the text you want to translate, in and the language pair, lang.

Request block example:

{
  "in": "Translation text",
  "lang": "en-tw"
}
  • in: (Required) The input string to be translated. The maximum length is 1000 characters.

  • lang: (Required) The language pair tag in the format from-to. For example, en-tw for English to Twi.

Supported Language Codes

I honestly had no idea Gurene was a Ghanaian language until I explored the GhanaNLP platform. It really struck me when I realized I'm living in my motherland and don't know enough about it. Well, there are eleven (11) languages available to use as pairs in the request block.

These languages are:

Example Request

Here’s what a JSON request looks like if you want to translate from English to Twi:

{
  "in": "Hello, how are you?",
  "lang": "en-tw"
}

The expected output is as follows:

The Response Structure

When your request goes through successfully, you’ll get a JSON response with the translated text.

Response Example:

{
  "type": "string",
  "description": "Translated text"
}
  • type: The type of response (usually a string).

  • description: The translated text.

Handling Errors

If something goes wrong, like using an unsupported language code or leaving out required information, the API will return an error message with a 400 status code.

Error Response Example:

{
  "type": "Error type",
  "message": "Error message"
}

Common Error Types

  • Invalid language code: The lang parameter contains an unsupported language code.

  • Input too long: The input text exceeds the character limit.

Whether you’re a developer or a researcher, integrating this API into your projects can significantly expand your reach by enabling support for local languages. It’s a powerful tool for making tech more inclusive. Happy learning!


For more information, you can check out these additional resources: