aws-translate-json
v0.0.3
Published
Translate object values into other languages using the AWS translate API
Maintainers
Readme
AWS Translate JSON
Translate object values into other languages using the AWS translate API
Install as a npm package
npm install aws-translate-json
Usage
Create an AWS account (Skip this step if you already have one):
- Create an account here.
There is a free tier to use the translation API that you can check here.
Create an IAM account with AWS Translation permissions only (Recommended):
- Login on AWS console and navigate to IAM panel
- Click on
Userstab - Click on
Add Userbutton - Follow the steps and add a
Userwith access to the Translation API only - Store the
access keyand thesecretin a secure place
Usage example:
const { AWSTranslateJSON } = require('aws-translate-json');
const awsConfig = {
accessKeyId: process.env.AWS_TRANSLATE_ID,
secretAccessKey: process.env.AWS_TRANSLATE_SECRET,
region: process.env.AWS_TRANSLATE_REGION,
}
const source = "en";
const taget = ["pt", "it", "es"];
const { translateJSON } = new AWSTranslateJSON(awsConfig, source, taget);
translateJSON({
key1: "my text here",
key2: "other text",
key3: {
key4: "nested text"
}
}).then(console.log);
/* OUTPUT:
{
pt: {
key1: 'meu texto aqui',
key2: 'outro texto',
key3: {
key4: 'texto aninhado'
}
},
it: {
key1: 'il mio testo qui',
key2: 'altro testo',
key3: {
key4: 'testo nidificato'
}
},
es: {
key1: 'mi texto aquí',
key2: 'otro texto',
key3: {
key4: 'texto anidado'
}
}
}
*/