@fiit/localisation
v1.1.19
Published
Localisation service by Fiit
Downloads
93
Keywords
Readme
Localisation Service
This TypeScript library provides an interface to the AWS Translate service, enabling both single text and batch text translations. It supports dynamic language detection and translation into specified target languages.
Features
- Translate individual strings.
- Batch translate arrays of strings while preserving order.
- Automatically detect source language.
Installation
Install the package using npm. Ensure you have Node.js installed before running the following command:
npm install @fiit/localisation
Configuration
You must provide AWS credentials and a region to use this service. For security, it is recommended to manage credentials through environment variables or AWS IAM roles instead of hard coding them.
Usage
Import the Localisation, Language, and configuration interface from the package:
import { Localisation, Language, LocalisationConfig } from '@fiit/localisation';
const config: LocalisationConfig = {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: process.env.AWS_REGION
};
const localisationService = new Localisation(config);
Translating Text
To translate a single piece of text:
const translation = await localisationService.translateText("Hello, world!", Language.EN);
Batch Translation
To translate multiple texts at once:
const texts = ["Hello, world!", "How are you?"];
const translations = await localisationService.translateBatchText(texts, Language.ES);