Package translate :: Package storage :: Module tbx
[hide private]
[frames] | no frames]

Source Code for Module translate.storage.tbx

 1  #!/usr/bin/env python 
 2  # -*- coding: utf-8 -*- 
 3  # 
 4  # Copyright 2006-2010 Zuza Software Foundation 
 5  # 
 6  # This file is part of the Translate Toolkit. 
 7  # 
 8  # This program is free software; you can redistribute it and/or modify 
 9  # it under the terms of the GNU General Public License as published by 
10  # the Free Software Foundation; either version 2 of the License, or 
11  # (at your option) any later version. 
12  # 
13  # This program is distributed in the hope that it will be useful, 
14  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
16  # GNU General Public License for more details. 
17  # 
18  # You should have received a copy of the GNU General Public License 
19  # along with this program; if not, see <http://www.gnu.org/licenses/>. 
20   
21  """module for handling TBX glossary files""" 
22   
23  from lxml import etree 
24   
25  from translate.storage import lisa 
26   
27   
28 -class tbxunit(lisa.LISAunit):
29 """A single term in the TBX file. 30 Provisional work is done to make several languages possible.""" 31 rootNode = "termEntry" 32 languageNode = "langSet" 33 textNode = "term" 34
35 - def createlanguageNode(self, lang, text, purpose):
36 """returns a langset xml Element setup with given parameters""" 37 if isinstance(text, str): 38 text = text.decode("utf-8") 39 langset = etree.Element(self.languageNode) 40 lisa.setXMLlang(langset, lang) 41 tig = etree.SubElement(langset, "tig") # or ntig with termGrp inside 42 term = etree.SubElement(tig, self.textNode) 43 # probably not what we want: 44 # lisa.setXMLspace(term, "preserve") 45 term.text = text 46 return langset
47
48 - def getid(self):
49 # The id attribute is optional 50 return self.xmlelement.get("id") or self.source
51 52
53 -class tbxfile(lisa.LISAfile):
54 """Class representing a TBX file store.""" 55 UnitClass = tbxunit 56 Name = _("TBX Glossary") 57 Mimetypes = ["application/x-tbx"] 58 Extensions = ["tbx"] 59 rootNode = "martif" 60 bodyNode = "body" 61 XMLskeleton = '''<?xml version="1.0"?> 62 <!DOCTYPE martif PUBLIC "ISO 12200:1999A//DTD MARTIF core (DXFcdV04)//EN" "TBXcdv04.dtd"> 63 <martif type="TBX"> 64 <martifHeader> 65 <fileDesc> 66 <sourceDesc><p>Translate Toolkit</p></sourceDesc> 67 </fileDesc> 68 </martifHeader> 69 <text><body></body></text> 70 </martif>''' 71
72 - def addheader(self):
73 """Initialise headers with TBX specific things.""" 74 lisa.setXMLlang(self.document.getroot(), self.sourcelanguage)
75