Ejemplo n.º 1
0
 def test_diff_whitespace(self):
     self.assertHTMLEqual(
         format_translation(
             "Helloworld",
             self.component.source_language,
             diff="Hello world",
         )["items"][0]["content"],
         """Hello
         <del>
             <span class="hlspace">
                 <span class="space-space"><span class="sr-only"> </span></span>
             </span>
         </del>
         world
         """,
     )
     self.assertHTMLEqual(
         format_translation(
             "Hello world",
             self.component.source_language,
             diff="Helloworld",
         )["items"][0]["content"],
         """Hello
         <ins>
             <span class="hlspace">
                 <span class="space-space"><span class="sr-only"> </span></span>
             </span>
         </ins>
         world
         """,
     )
Ejemplo n.º 2
0
 def test_glossary_space(self):
     self.assertHTMLEqual(
         format_translation(
             "text  Hello world",
             self.component.source_language,
             glossary=[
                 Unit(source="hello",
                      target="ahoj",
                      translation=self.translation)
             ],
         )["items"][0]["content"],
         """
         text
         <span class="hlspace">
             <span class="space-space">
                 <span class="sr-only"> </span>
             </span>
             <span class="space-space">
                 <span class="sr-only"> </span>
             </span>
         </span>
         <span class="glossary-term"
             title="Glossary translation: ahoj">Hello</span>
         world
         """,
     )
Ejemplo n.º 3
0
 def test_fmtsearchmatch(self):
     self.assertEqual(
         format_translation("Hello world!",
                            MockLanguage("en"),
                            search_match="hello")["items"][0]["content"],
         '<span class="hlmatch">Hello</span> world!',
     )
Ejemplo n.º 4
0
 def html_diff(self, diff, source):
     unit = MockUnit(source=source)
     return format_translation(
         unit.source,
         unit.translation.component.source_language,
         diff=diff,
     )["items"][0]["content"]
Ejemplo n.º 5
0
 def test_fmtsearchmatch(self):
     self.assertEqual(
         format_translation(
             'Hello world!', MockLanguage('en'), search_match='hello'
         )['items'][0]['content'],
         '<span class="hlmatch">Hello</span> world!',
     )
Ejemplo n.º 6
0
 def test_basic(self):
     self.assertEqual(
         format_translation("Hello world", self.component.source_language,)["items"][
             0
         ]["content"],
         "Hello world",
     )
Ejemplo n.º 7
0
 def test_format_diff(self):
     unit = MockUnit(source='Hello word!')
     self.assertEqual(
         format_translation(
             unit.source,
             unit.translation.component.project.source_language,
             diff='Hello world!',
         )['items'][0]['content'], 'Hello wor<del>l</del>d!')
Ejemplo n.º 8
0
 def test_fmtsearchmatch(self):
     self.assertEqual(
         format_translation(
             'Hello world!',
             search_match='hello'
         )['items'][0]['content'],
         u'<span class="hlmatch">Hello</span> world!'
     )
Ejemplo n.º 9
0
 def test_format_diff(self):
     unit = MockUnit(source='Hello word!')
     self.assertEqual(
         format_translation(
             unit.source,
             diff='Hello world!',
         )['items'][0]['content'],
         u'Hello wor<del>l</del>d!'
     )
Ejemplo n.º 10
0
 def test_search(self):
     self.assertHTMLEqual(
         format_translation(
             "Hello world",
             self.component.source_language,
             search_match="world",
         )["items"][0]["content"],
         """Hello <span class="hlmatch">world</span>""",
     )
Ejemplo n.º 11
0
 def test_format_diff(self):
     unit = MockUnit(source="Hello word!")
     self.assertEqual(
         format_translation(
             unit.source,
             unit.translation.component.source_language,
             diff="Hello world!",
         )["items"][0]["content"],
         "Hello wor<del>l</del>d!",
     )
Ejemplo n.º 12
0
 def test_format_entities(self):
     unit = MockUnit(source="'word'")
     self.assertEqual(
         format_translation(
             unit.source,
             unit.translation.component.source_language,
             diff='"word"',
         )["items"][0]["content"],
         "<del>&quot;</del><ins>&#x27;</ins>word<del>&quot;</del><ins>&#x27;</ins>",
     )
Ejemplo n.º 13
0
 def test_format_diff(self):
     unit = MockUnit(source='Hello word!')
     self.assertEqual(
         format_translation(
             unit.source,
             unit.translation.component.project.source_language,
             diff='Hello world!',
         )['items'][0]['content'],
         'Hello wor<del>l</del>d!'
     )
Ejemplo n.º 14
0
 def test_format_diff_whitespace(self):
     unit = MockUnit(source="Hello world!")
     self.assertEqual(
         format_translation(
             unit.source,
             unit.translation.component.source_language,
             diff="Hello world! ",
         )["items"][0]["content"],
         'Hello world!<del><span class="space-space">'
         '<span class="sr-only"> </span></span></del>',
     )
Ejemplo n.º 15
0
 def test_glossary_brackets(self):
     self.assertHTMLEqual(
         format_translation(
             "[Hello] world",
             self.component.source_language,
             glossary=[
                 Unit(source="[hello]", target="ahoj", translation=self.translation)
             ],
         )["items"][0]["content"],
         """
         <span class="glossary-term"
             title="Glossary translation: ahoj">[Hello]</span>
         world
         """,
     )
Ejemplo n.º 16
0
 def test_whitespace_special(self):
     self.assertHTMLEqual(
         format_translation(
             "Hello\u00A0world",
             self.component.source_language,
         )["items"][0]["content"],
         """
         Hello
         <span class="hlspace">
             <span class="space-space" title="NO-BREAK SPACE">
                 <span class="sr-only">\u00A0</span>
             </span>
         </span>
         world
         """,
     )
Ejemplo n.º 17
0
 def test_highlight(self):
     unit = self.translation.unit_set.get(id_hash=2097404709965985808)
     self.assertHTMLEqual(
         format_translation(unit.source, unit.translation.language, unit=unit,)[
             "items"
         ][0]["content"],
         """
         Orangutan has
         <span class="hlcheck"><span class="highlight-number"></span>%d</span>
         banana.<span class="hlspace"><span class="space-nl"><span class="sr-only">
         </span>
         </span>
         </span>
         <br/>
         """,
     )
Ejemplo n.º 18
0
 def test_glossary_escape(self):
     self.assertHTMLEqual(
         format_translation(
             "Hello world",
             self.component.source_language,
             glossary=[
                 Unit(source="hello",
                      target='<b>ahoj"',
                      translation=self.translation)
             ],
         )["items"][0]["content"],
         """
         <span class="glossary-term"
             title="Glossary translation: &lt;b&gt;ahoj&quot;">Hello</span>
         world
         """,
     )
Ejemplo n.º 19
0
 def test_glossary_multi(self):
     self.assertHTMLEqual(
         format_translation(
             "Hello glossary",
             self.component.source_language,
             glossary=[
                 Unit(source="hello", target="ahoj", translation=self.translation),
                 Unit(
                     source="glossary", target="glosář", translation=self.translation
                 ),
             ],
         )["items"][0]["content"],
         """
         <span class="glossary-term"
             title="Glossary translation: ahoj">Hello</span>
         <span class="glossary-term"
             title="Glossary translation: glosář">glossary</span>
         """,
     )
Ejemplo n.º 20
0
 def test_whitespace_newline(self):
     self.assertHTMLEqual(
         format_translation("Hello\n world", self.component.source_language,)[
             "items"
         ][0]["content"],
         """
         Hello
         <span class="hlspace">
             <span class="space-nl">
                 <span class="sr-only"> </span>
             </span>
         </span><br>
         <span class="hlspace">
             <span class="space-space">
                 <span class="sr-only"> </span>
             </span>
         </span>
         world
         """,
     )
Ejemplo n.º 21
0
 def test_glossary_format(self):
     unit = Unit()
     unit.all_flags = {"php-format"}
     self.assertHTMLEqual(
         format_translation(
             "%3$sHow",
             self.component.source_language,
             glossary=[
                 Unit(source="show",
                      target="zobrazit",
                      translation=self.translation),
             ],
             unit=unit,
         )["items"][0]["content"],
         """
         <span class="hlcheck" data-value="%3$s">
         <span class="highlight-number"></span>
         %3$s
         </span>
         How
         """,
     )