def translate_text( self, request: translation_service.TranslateTextRequest = None, *, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> translation_service.TranslateTextResponse: r"""Translates input text and returns translated text. Args: request (:class:`~.translation_service.TranslateTextRequest`): The request object. The request message for synchronous translation. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.translation_service.TranslateTextResponse: """ # Create or coerce a protobuf request object. # Minor optimization to avoid making a copy if the user passes # in a translation_service.TranslateTextRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. if not isinstance(request, translation_service.TranslateTextRequest): request = translation_service.TranslateTextRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.translate_text] # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata( (("parent", request.parent), )), ) # Send the request. response = rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Done; return the response. return response
async def translate_text( self, request: translation_service.TranslateTextRequest = None, *, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> translation_service.TranslateTextResponse: r"""Translates input text and returns translated text. Args: request (:class:`google.cloud.translate_v3beta1.types.TranslateTextRequest`): The request object. The request message for synchronous translation. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: google.cloud.translate_v3beta1.types.TranslateTextResponse: """ # Create or coerce a protobuf request object. request = translation_service.TranslateTextRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.translate_text, default_timeout=600.0, client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata( (("parent", request.parent), )), ) # Send the request. response = await rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Done; return the response. return response