def addalttrans(self, txt, origin=None, lang=None, sourcetxt=None, matchquality=None): """Adds an alt-trans tag and alt-trans components to the unit. @type txt: String @param txt: Alternative translation of the source text. """ #TODO: support adding a source tag ad match quality attribute. At # the source tag is needed to inject fuzzy matches from a TM. if isinstance(txt, str): txt = txt.decode("utf-8") alttrans = etree.SubElement(self.xmlelement, self.namespaced("alt-trans")) lisa.setXMLspace(alttrans, "preserve") if sourcetxt: if isinstance(sourcetxt, str): sourcetxt = sourcetxt.decode("utf-8") altsource = etree.SubElement(alttrans, self.namespaced("source")) altsource.text = sourcetxt alttarget = etree.SubElement(alttrans, self.namespaced("target")) alttarget.text = txt if matchquality: alttrans.set("match-quality", matchquality) if origin: alttrans.set("origin", origin) if lang: lisa.setXMLlang(alttrans, lang)
def addtranslation(self, source, srclang, translation, translang): """addtranslation method for testing old unit tests""" unit = self.addsourceunit(source) unit.target = translation tuvs = unit.xmlelement.iterdescendants(self.namespaced('tuv')) lisa.setXMLlang(tuvs.next(), srclang) lisa.setXMLlang(tuvs.next(), translang)
def createlanguageNode(self, lang, text, purpose): """returns a langset xml Element setup with given parameters""" if isinstance(text, str): text = text.decode("utf-8") langset = etree.Element(self.languageNode) lisa.setXMLlang(langset, lang) tig = etree.SubElement(langset, "tig") # or ntig with termGrp inside term = etree.SubElement(tig, self.textNode) term.text = text return langset
def createlanguageNode(self, lang, text, purpose): """returns a langset xml Element setup with given parameters""" if isinstance(text, str): text = text.decode("utf-8") langset = etree.Element(self.languageNode) lisa.setXMLlang(langset, lang) seg = etree.SubElement(langset, self.textNode) # implied by the standard: # lisa.setXMLspace(seg, "preserve") seg.text = text return langset
def addtranslation(self, source, srclang, translation, translang, comment=None): """addtranslation method for testing old unit tests""" unit = self.addsourceunit(source) unit.target = translation if comment is not None and len(comment) > 0: unit.addnote(comment) tuvs = unit.xmlelement.iterdescendants(self.namespaced('tuv')) lisa.setXMLlang(next(tuvs), srclang) lisa.setXMLlang(next(tuvs), translang)
def createlanguageNode(self, lang, text, purpose): """returns a langset xml Element setup with given parameters""" if isinstance(text, str): text = text.decode("utf-8") langset = etree.Element(self.languageNode) lisa.setXMLlang(langset, lang) tig = etree.SubElement(langset, "tig") # or ntig with termGrp inside term = etree.SubElement(tig, self.textNode) # probably not what we want: # lisa.setXMLspace(term, "preserve") term.text = text return langset
def createlanguageNode(self, lang, text, purpose): """returns a langset xml Element setup with given parameters""" if isinstance(text, bytes): text = text.decode("utf-8") langset = etree.Element(self.languageNode) lisa.setXMLlang(langset, lang) tig = etree.SubElement(langset, "tig") # or ntig with termGrp inside term = etree.SubElement(tig, self.textNode) # probably not what we want: # lisa.setXMLspace(term, "preserve") term.text = text return langset
def addtranslation(self, source, srclang, translation, translang, comment=None): """addtranslation method for testing old unit tests""" unit = self.addsourceunit(source) unit.target = translation if comment is not None and len(comment) > 0: unit.addnote(comment) tuvs = unit.xmlelement.iterdescendants(self.namespaced('tuv')) lisa.setXMLlang(tuvs.next(), srclang) lisa.setXMLlang(tuvs.next(), translang)
def addheader(self): """Initialise headers with TBX specific things.""" lisa.setXMLlang(self.document.getroot(), self.sourcelanguage)