def get_conn(self) -> Client: """ Retrieves connection to Cloud Translate :return: Google Cloud Translate client object. :rtype: google.cloud.translate_v2.Client """ if not self._client: self._client = Client(credentials=self._get_credentials()) return self._client
def translation_client_from_json( json_credential_path: str) -> "GoogleTranslateClient": """ Returns a Google translation client based on credentials stored in a Google credential json file Args: json_credential_path: path to the google credential json file Returns: A Google Translate Client """ from google.cloud.translate_v2 import Client as GoogleTranslateClient LOGGER.info("Connecting to Google Translation Client") google_client = GoogleTranslateClient.from_service_account_json( json_credential_path) return google_client