import logging

from . import AbstractTranslationProvider
from google.cloud import translate


logger = logging.getLogger(__name__)


class GoogleTranslate(AbstractTranslationProvider):
    def translate(self, strings, target_language, source_language="en"):
        client = translate.Client()
        response = client.translate(
            strings, source_language=source_language, target_language=target_language
        )

        return list(map(lambda x: x["translatedText"], response))

import logging

from . import AbstractTranslationProvider


logger = logging.getLogger(__name__)


class GoogleTranslate(AbstractTranslationProvider):
    def translate(self, strings, target_language, source_language="en"):
        from google.cloud import translate

        client = translate.Client()
        response = client.translate(
            strings, source_language=source_language, target_language=target_language
        )

        return list(map(lambda x: x["translatedText"], response))

Enable test mocking for translate
Enable test mocking for translate

  import logging
  
  from . import AbstractTranslationProvider
- from google.cloud import translate
  
  
  logger = logging.getLogger(__name__)
  
  
  class GoogleTranslate(AbstractTranslationProvider):
      def translate(self, strings, target_language, source_language="en"):
+         from google.cloud import translate
+ 
          client = translate.Client()
          response = client.translate(
              strings, source_language=source_language, target_language=target_language
          )
  
          return list(map(lambda x: x["translatedText"], response))
  
Enable test mocking for translate
## Code Before:
import logging

from . import AbstractTranslationProvider
from google.cloud import translate


logger = logging.getLogger(__name__)


class GoogleTranslate(AbstractTranslationProvider):
    def translate(self, strings, target_language, source_language="en"):
        client = translate.Client()
        response = client.translate(
            strings, source_language=source_language, target_language=target_language
        )

        return list(map(lambda x: x["translatedText"], response))

## Instruction:
Enable test mocking for translate
## Code After:
import logging

from . import AbstractTranslationProvider


logger = logging.getLogger(__name__)


class GoogleTranslate(AbstractTranslationProvider):
    def translate(self, strings, target_language, source_language="en"):
        from google.cloud import translate

        client = translate.Client()
        response = client.translate(
            strings, source_language=source_language, target_language=target_language
        )

        return list(map(lambda x: x["translatedText"], response))
