How to use the googletrans.models.Translated function in googletrans

To help you get started, we’ve selected a few googletrans examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wagtail / wagtail-localize / wagtail_localize / translation / engines / google_translate / tests.py View on Github external
def test_translate(self, Translator):
        page = create_test_page(
            title="Test page",
            slug="test-page",
            test_charfield="Some translatable content",
            test_richtextfield="<p>Translatable <b>rich text</b></p>",
        )
        request_page = self.add_page_to_request(page)

        # Mock response from Google Translate
        Translator().translate.return_value = [
            Translated(
                "en",
                "fr",
                "Some translatable content",
                "Certains contenus traduisibles",
                "Certains contenus traduisibles",
            ),
            Translated(
                "en",
                "fr",
                "Translatable rich text",
                "Texte riche traduisible",
                "Texte riche traduisible",
            ),
        ]

        response = self.client.post(
github wagtail / wagtail-localize / wagtail_localize / translation / engines / google_translate / tests.py View on Github external
def test_translate_without_publishing(self, Translator):
        page = create_test_page(
            title="Test page",
            slug="test-page",
            test_charfield="Some translatable content",
        )
        request_page = self.add_page_to_request(page)

        # Mock response from Google Translate
        Translator().translate.return_value = [
            Translated(
                "en",
                "fr",
                "Some translatable content",
                "Certains contenus traduisibles",
                "Certains contenus traduisibles",
            )
        ]

        response = self.client.post(
            reverse(
                "wagtail_localize_google_translate:translate",
                args=[self.translation_request.id],
            )
        )

        self.assertRedirects(
github wagtail / wagtail-localize / wagtail_localize / translation / engines / google_translate / tests.py View on Github external
slug="test-page",
            test_charfield="Some translatable content",
            test_richtextfield="<p>Translatable <b>rich text</b></p>",
        )
        request_page = self.add_page_to_request(page)

        # Mock response from Google Translate
        Translator().translate.return_value = [
            Translated(
                "en",
                "fr",
                "Some translatable content",
                "Certains contenus traduisibles",
                "Certains contenus traduisibles",
            ),
            Translated(
                "en",
                "fr",
                "Translatable rich text",
                "Texte riche traduisible",
                "Texte riche traduisible",
            ),
        ]

        response = self.client.post(
            reverse(
                "wagtail_localize_google_translate:translate",
                args=[self.translation_request.id],
            ),
            {"publish": "on"},
        )
github wagtail / wagtail-localize / wagtail_localize / translation / engines / google_translate / tests.py View on Github external
def test_translate_with_nested_snippet(self, Translator):
        snippet = TestSnippet.objects.create(field="Some test snippet content")
        page = create_test_page(
            title="Test page", slug="test-page", test_snippet=snippet
        )
        request_page = self.add_page_to_request(page)

        # Mock response from Google Translate
        Translator().translate.return_value = [
            Translated(
                "en",
                "fr",
                "Some test snippet content",
                "Du contenu d'extrait de test",
                "Du contenu d'extrait de test",
            )
        ]

        response = self.client.post(
            reverse(
                "wagtail_localize_google_translate:translate",
                args=[self.translation_request.id],
            ),
            {"publish": "on"},
        )
github suliveevil / AppleScript / App-BetterAndBetter / BAB-PopClip / PopClipExtensions / googletranslate.popclipext / googletrans / client.py View on Github external
if not PY3 and isinstance(pron, unicode) and isinstance(origin, str):  # pragma: nocover
            origin = origin.decode('utf-8')
        if dest in EXCLUDES and pron == origin:
            pron = translated

        # for python 2.x compatbillity
        if not PY3:  # pragma: nocover
            if isinstance(src, str):
                src = src.decode('utf-8')
            if isinstance(dest, str):
                dest = dest.decode('utf-8')
            if isinstance(translated, str):
                translated = translated.decode('utf-8')

        # put final values into a new Translated object
        result = Translated(src=src, dest=dest, origin=origin,
                            text=translated, pronunciation=pron, extra_data=extra_data)

        return result
github michaeldegroot / cats-blender-plugin / googletrans / client.py View on Github external
if not PY3 and isinstance(pron, unicode) and isinstance(origin, str):  # pragma: nocover
            origin = origin.decode('utf-8')
        if dest in EXCLUDES and pron == origin:
            pron = translated

        # for python 2.x compatbillity
        if not PY3:  # pragma: nocover
            if isinstance(src, str):
                src = src.decode('utf-8')
            if isinstance(dest, str):
                dest = dest.decode('utf-8')
            if isinstance(translated, str):
                translated = translated.decode('utf-8')

        # put final values into a new Translated object
        result = Translated(src=src, dest=dest, origin=origin,
                            text=translated, pronunciation=pron)

        return result
github ssut / py-googletrans / googletrans / client.py View on Github external
if not PY3 and isinstance(pron, unicode) and isinstance(origin, str):  # pragma: nocover
            origin = origin.decode('utf-8')
        if dest in EXCLUDES and pron == origin:
            pron = translated

        # for python 2.x compatbillity
        if not PY3:  # pragma: nocover
            if isinstance(src, str):
                src = src.decode('utf-8')
            if isinstance(dest, str):
                dest = dest.decode('utf-8')
            if isinstance(translated, str):
                translated = translated.decode('utf-8')

        # put final values into a new Translated object
        result = Translated(src=src, dest=dest, origin=origin,
                            text=translated, pronunciation=pron, extra_data=extra_data)

        return result