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-2007 Zuza Software Foundation
     5  #
     6  # This file is part of translate.
     7  #
     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.
    12  #
    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.
    17  #
    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
    21  #
    22
    23  """module for handling TBX glossary files"""
    24
    25  from translate.storage import lisa
    26  from lxml import etree
    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          term.text = text
    44          return langset
    45
    46
    47 -class tbxfile(lisa.LISAfile):
    48      """Class representing a TBX file store."""
    49      UnitClass = tbxunit
    50      Name = _("TBX Glossary")
    51      Mimetypes  = ["application/x-tbx"]
    52      Extensions = ["tbx"]
    53      rootNode = "martif"
    54      bodyNode = "body"
    55      XMLskeleton = '''<?xml version="1.0"?>
    56  <!DOCTYPE martif PUBLIC "ISO 12200:1999A//DTD MARTIF core (DXFcdV04)//EN" "TBXcdv04.dtd">
    57  <martif type="TBX">
    58  <martifHeader>
    59  <fileDesc>
    60  <sourceDesc><p>Translate Toolkit - csv2tbx</p></sourceDesc>
    61  </fileDesc>
    62  </martifHeader>
    63  <text><body></body></text>
    64  </martif>'''
    65
    66 -    def addheader(self):
    67          """Initialise headers with TBX specific things."""
    68          lisa.setXMLlang(self.document.getroot(), self.sourcelanguage)
    69