Ejemplo n.º 1
0
 def test_translate_xml_with_namespace(self):
     """ Test xml_translate() on elements with namespaces. """
     terms = []
     # do not slit the long line below, otherwise the result will not match
     source = """<Invoice xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
                     <cbc:UBLVersionID t-esc="version_id"/>
                     <t t-foreach="[1, 2, 3, 4]" t-as="value">
                         Oasis <cac:Test t-esc="value"/>
                     </t>
                 </Invoice>"""
     result = xml_translate(terms.append, source)
     self.assertEquals(result, source)
     self.assertItemsEqual(terms, ['Oasis'])
     result = xml_translate(lambda term: term, source)
     self.assertEquals(result, source)
Ejemplo n.º 2
0
 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])
Ejemplo n.º 3
0
 def test_translate_xml_unicode(self):
     """ Test xml_translate() on plain text with unicode characters. """
     terms = []
     source = u"Un heureux évènement"
     result = xml_translate(terms.append, source)
     self.assertEquals(result, source)
     self.assertItemsEqual(terms, [source])
Ejemplo n.º 4
0
 def test_translate_html_i(self):
     """ Test xml_translate() and html_translate() with <i> elements. """
     source = """<p>A <i class="fa-check"></i> B</p>"""
     result = xml_translate(lambda term: term, source)
     self.assertEquals(result, """<p>A <i class="fa-check"/> B</p>""")
     result = html_translate(lambda term: term, source)
     self.assertEquals(result, source)
Ejemplo n.º 5
0
 def test_translate_xml_text_entity(self):
     """ Test xml_translate() on plain text with HTML escaped entities. """
     terms = []
     source = "Blah&amp;nbsp;blah&amp;nbsp;blah"
     result = xml_translate(terms.append, source)
     self.assertEquals(result, source)
     self.assertItemsEqual(terms, [source])
Ejemplo n.º 6
0
 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])
Ejemplo n.º 7
0
 def test_translate_html_i(self):
     """ Test xml_translate() and html_translate() with <i> elements. """
     source = """<p>A <i class="fa-check"></i> B</p>"""
     result = xml_translate(lambda term: term, source)
     self.assertEquals(result, """<p>A <i class="fa-check"/> B</p>""")
     result = html_translate(lambda term: term, source)
     self.assertEquals(result, source)
Ejemplo n.º 8
0
 def test_translate_xml_text_entity(self):
     """ Test xml_translate() on plain text with HTML escaped entities. """
     terms = []
     source = "Blah&amp;nbsp;blah&amp;nbsp;blah"
     result = xml_translate(terms.append, source)
     self.assertEquals(result, source)
     self.assertItemsEqual(terms, [source])
Ejemplo n.º 9
0
 def test_translate_xml_unicode(self):
     """ Test xml_translate() on plain text with unicode characters. """
     terms = []
     source = u"Un heureux évènement"
     result = xml_translate(terms.append, source)
     self.assertEquals(result, source)
     self.assertItemsEqual(terms, [source])
Ejemplo n.º 10
0
 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.assertEqual(result, source)
     self.assertItemsEqual(terms, ['Translate this'])
Ejemplo n.º 11
0
 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.assertEqual(result, source)
     self.assertItemsEqual(terms, ['stuff before', 'stuff after'])
Ejemplo n.º 12
0
 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'])
Ejemplo n.º 13
0
 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.assertEqual(result, source)
     self.assertItemsEqual(terms, ['stuff before', 'stuff after'])
Ejemplo n.º 14
0
 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'])
Ejemplo n.º 15
0
 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'])
Ejemplo n.º 16
0
 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'])
Ejemplo n.º 17
0
 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.assertEqual(result, source)
     self.assertItemsEqual(
         terms, ['Form stuff', 'Blah blah blah', 'Put some more text here'])
Ejemplo n.º 18
0
 def test_translate_xml_inline5(self):
     """ Test xml_translate() with inline elements with empty translated attrs only. """
     terms = []
     source = """<form string="Form stuff">
                     <div>
                         <label for="stuff"/>
                         <span class="fa fa-globe" title=""/>
                     </div>
                 </form>"""
     result = xml_translate(terms.append, source)
     self.assertEqual(result, source)
     self.assertItemsEqual(terms, ['Form stuff'])
Ejemplo n.º 19
0
 def test_translate_xml_inline5(self):
     """ Test xml_translate() with inline elements with empty translated attrs only. """
     terms = []
     source = """<form string="Form stuff">
                     <div>
                         <label for="stuff"/>
                         <span class="fa fa-globe" title=""/>
                     </div>
                 </form>"""
     result = xml_translate(terms.append, source)
     self.assertEquals(result, source)
     self.assertItemsEqual(terms, ['Form stuff'])
Ejemplo n.º 20
0
 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'])
Ejemplo n.º 21
0
 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'])
Ejemplo n.º 22
0
 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.assertEqual(result, source)
     self.assertItemsEqual(terms, ['Form stuff', 'Blah blah blah'])
Ejemplo n.º 23
0
 def test_translate_xml_a(self):
     """ Test xml_translate() with <a> elements. """
     terms = []
     source = """<t t-name="stuff">
                     <ul class="nav navbar-nav">
                         <li class="nav-item">
                             <a class="nav-link oe_menu_leaf" href="/web#menu_id=42&amp;action=54">
                                 <span class="oe_menu_text">Blah</span>
                             </a>
                         </li>
                     </ul>
                 </t>"""
     result = xml_translate(terms.append, source)
     self.assertEqual(result, source)
     self.assertItemsEqual(terms,
                           ['<span class="oe_menu_text">Blah</span>'])
Ejemplo n.º 24
0
 def test_translate_xml_a(self):
     """ Test xml_translate() with <a> elements. """
     terms = []
     source = """<t t-name="stuff">
                     <ul class="nav navbar-nav">
                         <li class="nav-item">
                             <a class="nav-link oe_menu_leaf" href="/web#menu_id=42&amp;action=54">
                                 <span class="oe_menu_text">Blah</span>
                             </a>
                         </li>
                     </ul>
                 </t>"""
     result = xml_translate(terms.append, source)
     self.assertEquals(result, source)
     self.assertItemsEqual(terms,
         ['<span class="oe_menu_text">Blah</span>'])
Ejemplo n.º 25
0
 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'])
Ejemplo n.º 26
0
 def test_translate_xml_invalid_translations(self):
     """ Test xml_translate() with invalid translations. """
     source = """<form string="Form stuff">
                     <h1>Blah <i>blah</i> blah</h1>
                     Put some <b>more text</b> here
                     <field name="foo"/>
                 </form>"""
     translations = {
         "Put some <b>more text</b> here": "Mettre <b>plus de texte</i> ici",
     }
     expect = """<form string="Form stuff">
                     <h1>Blah <i>blah</i> blah</h1>
                     Mettre &lt;b&gt;plus de texte&lt;/i&gt; ici
                     <field name="foo"/>
                 </form>"""
     result = xml_translate(translations.get, source)
     self.assertEquals(result, expect)
Ejemplo n.º 27
0
 def test_translate_xml_invalid_translations(self):
     """ Test xml_translate() with invalid translations. """
     source = """<form string="Form stuff">
                     <h1>Blah <i>blah</i> blah</h1>
                     Put some <b>more text</b> here
                     <field name="foo"/>
                 </form>"""
     translations = {
         "Put some <b>more text</b> here": "Mettre <b>plus de texte</i> ici",
     }
     expect = """<form string="Form stuff">
                     <h1>Blah <i>blah</i> blah</h1>
                     Mettre &lt;b&gt;plus de texte&lt;/i&gt; ici
                     <field name="foo"/>
                 </form>"""
     result = xml_translate(translations.get, source)
     self.assertEquals(result, expect)
Ejemplo n.º 28
0
 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&amp;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"/>'])