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 """, )
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 """, )
def test_fmtsearchmatch(self): self.assertEqual( format_translation("Hello world!", MockLanguage("en"), search_match="hello")["items"][0]["content"], '<span class="hlmatch">Hello</span> world!', )
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"]
def test_fmtsearchmatch(self): self.assertEqual( format_translation( 'Hello world!', MockLanguage('en'), search_match='hello' )['items'][0]['content'], '<span class="hlmatch">Hello</span> world!', )
def test_basic(self): self.assertEqual( format_translation("Hello world", self.component.source_language,)["items"][ 0 ]["content"], "Hello world", )
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!')
def test_fmtsearchmatch(self): self.assertEqual( format_translation( 'Hello world!', search_match='hello' )['items'][0]['content'], u'<span class="hlmatch">Hello</span> world!' )
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!' )
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>""", )
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!", )
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>"</del><ins>'</ins>word<del>"</del><ins>'</ins>", )
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!' )
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>', )
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 """, )
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 """, )
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/> """, )
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: <b>ahoj"">Hello</span> world """, )
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> """, )
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 """, )
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 """, )