fix git support for v1.5.3 (or higher) by setting "--work-tree"
[translate_toolkit.git] / storage / tbx.py
blob936ef11d0e8dccd0138554c1cfeab7c8b625cffa
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 # Copyright 2006-2007 Zuza Software Foundation
5 #
6 # This file is part of translate.
8 # translate 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.
13 # translate 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.
18 # You should have received a copy of the GNU General Public License
19 # along with translate; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 """module for handling TBX glossary files"""
25 from translate.storage import lisa
26 from lxml import etree
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"
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 term.text = text
44 return langset
47 class tbxfile(lisa.LISAfile):
48 """Class representing a TBX file store."""
49 UnitClass = tbxunit
50 rootNode = "martif"
51 bodyNode = "body"
52 XMLskeleton = '''<?xml version="1.0"?>
53 <!DOCTYPE martif PUBLIC "ISO 12200:1999A//DTD MARTIF core (DXFcdV04)//EN" "TBXcdv04.dtd">
54 <martif type="TBX">
55 <martifHeader>
56 <fileDesc>
57 <sourceDesc><p>Translate Toolkit - csv2tbx</p></sourceDesc>
58 </fileDesc>
59 </martifHeader>
60 <text><body></body></text>
61 </martif>'''
63 def addheader(self):
64 """Initialise headers with TBX specific things."""
65 lisa.setXMLlang(self.document.getroot(), self.sourcelanguage)