From the command line run:
npm install @saws/translate
Then add the TranslateService
to your saws.js
file.
When running your SAWS application in development, this service will do nothing. Important to note that the Translate
library will still hit AWS's translation services when running in development.
When you deploy a TranslateService
it will not create any resources in AWS. This service primarily functions as a way to ensure any dependant services have the right permissions set up.
@saws/translate
includes one service, TranslateService
.
You can require the TranslateService
and use it in your saws.js
file like so:
const { TranslateService } = require('@saws/translate/translate-service')
// will exclusively be used as a dependency to other services
const translate = new TranslateService({
name: 'translate-service',
})
The TranslateService
constructor accepts the following options:
The name of your service. This should be unique across all of your services.
An array of all of the other services this service depends on. This will ensure that permissions, environment variables, and execution order are all set up.
When a TranslateService
is used as a dependency, it will not attach any environment variables to the dependant service.
@saws/translate
includes a Translate
class that can be used to get machine translations from AWS's translation services.
The Translate
class can be used as follows:
import { Translate } from '@saws/translate/translate-library'
const client = new Translate()
const result = await client.translateText('Some text', sourceLanguage, targetLanguage)
This function will use AWS's translation services to perform a machine translation of the provided text from the source language to the target language.