コード例 #1
0
    def test_translation_contains_wrong_extra_tag(self) -> None:
        """The translation references an tag that wasn't in the initial string."""

        translate = _create_translate_func({
            '{0}/accueil': '{1}/home',
            'Bob': 'Bob',
        })
        with self.assertRaises(KeyError):
            translate_mailjet.translate_html_tags(
                '<a href="{{var:baseUrl}}/accueil">Bob</a>', translate)
コード例 #2
0
    def test_no_html(self) -> None:
        """Translate HTML tags with no tags."""

        translate = _create_translate_func({'No tags': 'Pas de tags'})
        self.assertEqual(
            'Pas de tags',
            translate_mailjet.translate_html_tags('No tags', translate))
コード例 #3
0
    def test_br_tag(self) -> None:
        """Translate HTML tags with a br implicitely self closing tag."""

        translate = _create_translate_func(
            {'One <0/>self closing tag': 'Un <0/>tag autofermant'})
        self.assertEqual(
            'Un <br>tag autofermant',
            translate_mailjet.translate_html_tags('One <br>self closing tag',
                                                  translate))
コード例 #4
0
    def test_simple_html_tag(self) -> None:
        """Translate HTML tags with one tag."""

        translate = _create_translate_func(
            {'One <0>tag</0>': 'Un seul <0>tag</0>'})
        self.assertEqual(
            'Un seul <span style="font-weight: 500">tag</span>',
            translate_mailjet.translate_html_tags(
                'One <span style="font-weight: 500">tag</span>', translate))
コード例 #5
0
    def test_attributes_no_i18n(self) -> None:
        """Do not translate HTML attributes if they don't need it."""

        translate = _create_translate_func(
            {'<0>Bob</0> is cool': '<0>Bob</0> est frais'})
        self.assertEqual(
            '<a href="{{var:deepBobUrl}}">Bob</a> est frais',
            translate_mailjet.translate_html_tags(
                '<a href="{{var:deepBobUrl}}">Bob</a> is cool', translate))
コード例 #6
0
    def test_external_attributes(self) -> None:
        """Translate HTML attributes even in the outside tags."""

        translate = _create_translate_func({
            'https://uk.hellobob.com': 'https://www.bob-emploi.fr',
            'Bob': 'Bob',
        })
        self.assertEqual(
            '<a href="https://www.bob-emploi.fr">Bob</a>',
            translate_mailjet.translate_html_tags(
                '<a href="https://uk.hellobob.com">Bob</a>', translate))
コード例 #7
0
    def test_attributes_i18n(self) -> None:
        """Translate HTML attributes if they need it."""

        translate = _create_translate_func({
            '<0>Bob</0> is cool': '<0>Bob</0> est frais',
            '{0}/home': '{0}/accueil',
        })
        self.assertEqual(
            '<a href="{{var:deepBobUrl}}/accueil">Bob</a> est frais',
            translate_mailjet.translate_html_tags(
                '<a href="{{var:deepBobUrl}}/home">Bob</a> is cool',
                translate))
コード例 #8
0
    def test_multiple_tags(self) -> None:
        """Translate HTML tags with multiple nested tags."""

        translate = _create_translate_func({
            'Multiple <0>nested</0><1/>tags':
            'Plusieurs tags <0>imbriqués</0>'
        })
        self.assertEqual(
            '<p>Plusieurs tags <strong>imbriqués</strong></p>',
            translate_mailjet.translate_html_tags(
                '<p>Multiple <strong>nested</strong><br />tags</p>',
                translate))
コード例 #9
0
    def test_identical_tags(self) -> None:
        """Translate HTML tags with multiple identical tags."""

        translate = _create_translate_func({
            'Multiple <0>identical</0><1/><0>tags</0>':
            'Plusieurs <0>tags</0><1/><0>identiques</0>'
        })
        self.assertEqual(
            'Plusieurs <strong>tags</strong><br /><strong>identiques</strong>',
            translate_mailjet.translate_html_tags(
                'Multiple <strong>identical</strong><br /><strong>tags</strong>',
                translate))
コード例 #10
0
    def test_translation_contains_extra_tag(self) -> None:
        """The translation contains an MJML tag that wasn't in the initial string."""

        translate = _create_translate_func({
            'https://www.facebook.com/pg/Wantedcommunity/':
            '{{var:baseUrl}}/covid-19',
            'Contact Wanted':
            'See our recommendations',
        })
        self.assertEqual(
            '<a href="{{var:baseUrl}}/covid-19">See our recommendations</a>',
            translate_mailjet.translate_html_tags(
                '<a href="https://www.facebook.com/pg/Wantedcommunity/">Contact Wanted</a>',
                translate))