- Create API Key in Google Cloud on the site https://console.cloud.google.com/apis/credentials
- Integrate API Key in the Module
@Module({
imports: [
NestGoogleTranslatorModule.forRootAsync({
useFactory: () => ({
apiKey: "***************",
}),
}),
],
})
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
Error type
{
code: string;
name: string;
message: string;
}
- Any error return
code = 'error'