Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@hawkbas/nest-google-translator

alexanderbeichuk35UNLICENSED1.0.0TypeScript support: included

Google translator

nest, nestjs, traslation, google, Translation API, async

readme

Integrate Google Translate API into your NestJS app

Integrate Google api-key

  1. Create API Key in Google Cloud on the site https://console.cloud.google.com/apis/credentials
  2. Integrate API Key in the Module
    @Module({
     imports: [
         NestGoogleTranslatorModule.forRootAsync({
             useFactory: () => ({
                 apiKey: "***************",
             }),
         }),
     ],
    })

Service included 3 async methods

Integrate service NestGoogleTranslatorService in your app for use methods:

  • detectLanguage(text: string): Promise<Language | TranslatorError> - Automatic language detection based on text
  • getSupportedLanguages(): Promise<Language[] | TranslatorError> - Get all supported languages
  • translate(text: string, targetLanguageCode: string, options: TranslateOptions): Promise<TranslateResponse | TranslatorError> - Translates text

Errors (TranslatorError)

Error type

{
    code: string;
    name: string;
    message: string;
}
  • Any error return code = 'error'