2 # -*- coding: utf-8 -*-
4 # Copyright 2006-2007 Zuza Software Foundation
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"
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
)
47 class tbxfile(lisa
.LISAfile
):
48 """Class representing a TBX file store."""
52 XMLskeleton
= '''<?xml version="1.0"?>
53 <!DOCTYPE martif PUBLIC "ISO 12200:1999A//DTD MARTIF core (DXFcdV04)//EN" "TBXcdv04.dtd">
57 <sourceDesc><p>Translate Toolkit - csv2tbx</p></sourceDesc>
60 <text><body></body></text>
64 """Initialise headers with TBX specific things."""
65 lisa
.setXMLlang(self
.document
.getroot(), self
.sourcelanguage
)