How to use googletrans - 10 common examples

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 ssut / py-googletrans / tests / test_utils.py View on Github external
def test_rshift():
    value, n = 1000, 3

    result = utils.rshift(value, n)

    assert result == 125
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 ssut / py-googletrans / tests / test_utils.py View on Github external
def test_format_json():
    text = '[,,"en",,,,0.96954316,,[["en"],,[0.96954316]]]'

    result = utils.legacy_format_json(text)

    assert result == [None, None, 'en', None, None, None, 0.96954316, None,
                      [['en'], None, [0.96954316]]]
github ssut / py-googletrans / tests / test_utils.py View on Github external
def test_format_malformed_json():
    text = '[,,"en",,,,0.96954316,,[["en"],,0.96954316]]]'

    with raises(ValueError):
        utils.legacy_format_json(text)
github ssut / py-googletrans / tests / test_gtoken.py View on Github external
def acquirer():
    return gtoken.TokenAcquirer()
github ssut / py-googletrans / tests.py View on Github external
def test_latin_to_english(self):
        result = translator.translate('veritas lux mea', src='la', dest='en')
        assert result.text == 'The truth is my light'
github ssut / py-googletrans / tests.py View on Github external
def test_list_translation(self):
        translations = translator.translate(['The quick brown fox', 'jumps over', 'the lazy dog'],
            src='en', dest='ko')

        assert translations[0].text == u'빠른 갈색 여우'
        assert translations[1].text == u'이상 점프'
        assert translations[2].text == u'게으른 개'