def test_translate_xml_text_entity(self): """ Test xml_translate() on plain text with HTML escaped entities. """ terms = [] source = "Blah blah blah" result = xml_translate(terms.append, source) self.assertEquals(result, source) self.assertItemsEqual(terms, [source])
def test_translate_html(self): """ Test xml_translate() and html_translate() with <i> elements. """ source = """<i class="fa-check"></i>""" result = xml_translate(lambda term: term, source) self.assertEquals(result, """<i class="fa-check"/>""") result = html_translate(lambda term: term, source) self.assertEquals(result, source)
def test_translate_xml_text(self): """ Test xml_translate() on plain text. """ terms = [] source = "Blah blah blah" result = xml_translate(terms.append, source) self.assertEquals(result, source) self.assertItemsEqual(terms, [source])
def test_translate_xml_attribute(self): """ Test xml_translate() with <attribute> elements. """ terms = [] source = """<field name="foo" position="attributes"> <attribute name="string">Translate this</attribute> <attribute name="option">Do not translate this</attribute> </field>""" result = xml_translate(terms.append, source) self.assertEquals(result, source) self.assertItemsEqual(terms, ['Translate this'])
def test_translate_xml_inline2(self): """ Test xml_translate() with formatting elements embedding other elements. """ terms = [] source = """<form string="Form stuff"> <b><h1>Blah <i>blah</i> blah</h1></b> Put <em>some <b>more text</b></em> here <field name="foo"/> </form>""" result = xml_translate(terms.append, source) self.assertEquals(result, source) self.assertItemsEqual(terms, ['Form stuff', 'Blah <i>blah</i> blah', 'Put <em>some <b>more text</b></em> here'])
def test_translate_xml_base(self): """ Test xml_translate() without formatting elements. """ terms = [] source = """<form string="Form stuff"> <h1>Blah blah blah</h1> Put some more text here <field name="foo"/> </form>""" result = xml_translate(terms.append, source) self.assertEquals(result, source) self.assertItemsEqual(terms, ['Form stuff', 'Blah blah blah', 'Put some more text here'])
def test_translate_xml_off(self): """ Test xml_translate() with attribute translate="off". """ terms = [] source = """<div> stuff before <div t-translation="off">Do not translate this</div> stuff after </div>""" result = xml_translate(terms.append, source) self.assertEquals(result, source) self.assertItemsEqual(terms, ['stuff before', 'stuff after'])
def test_translate_xml_t(self): """ Test xml_translate() with t-* attributes. """ terms = [] source = """<t t-name="stuff"> stuff before <span t-field="o.name"/> stuff after </t>""" result = xml_translate(terms.append, source) self.assertEquals(result, source) self.assertItemsEqual(terms, ['stuff before', 'stuff after'])
def test_translate_xml_inline3(self): """ Test xml_translate() with formatting elements without actual text. """ terms = [] source = """<form string="Form stuff"> <div> <span class="before"/> <h1>Blah blah blah</h1> <span class="after"> <i class="hack"/> </span> </div> </form>""" result = xml_translate(terms.append, source) self.assertEquals(result, source) self.assertItemsEqual(terms, ['Form stuff', 'Blah blah blah'])
def test_translate_xml_a(self): """ Test xml_translate() with <a> elements. """ terms = [] source = """<t t-name="stuff"> <ul class="nav navbar-nav"> <li> <a class="oe_menu_leaf" href="/web#menu_id=42&action=54"> <span class="oe_menu_text">Blah</span> </a> </li> <li class="dropdown" id="menu_more_container" style="display: none;"> <a class="dropdown-toggle" data-toggle="dropdown" href="#">More <b class="caret"/></a> <ul class="dropdown-menu" id="menu_more"/> </li> </ul> </t>""" result = xml_translate(terms.append, source) self.assertEquals(result, source) self.assertItemsEqual(terms, ['<span class="oe_menu_text">Blah</span>', 'More <b class="caret"/>'])