@hawkbas/nest-google-translator

1.0.0 • Public • Published

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'

Package Sidebar

Install

npm i @hawkbas/nest-google-translator

Weekly Downloads

7

Version

1.0.0

License

UNLICENSED

Unpacked Size

130 kB

Total Files

21

Last publish

Collaborators

  • alexanderbeichuk