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 translate.storage import lisa
    24  from lxml import etree
    25
    26 -class tbxunit(lisa.LISAunit):
    27      """A single term in the TBX file.
    28  Provisional work is done to make several languages possible."""
    29      rootNode = "termEntry"
    30      languageNode = "langSet"
    31      textNode = "term"
    32
    33 -    def createlanguageNode(self, lang, text, purpose):
    34          """returns a langset xml Element setup with given parameters"""
    35          if isinstance(text, str):
    36              text = text.decode("utf-8")
    37          langset = etree.Element(self.languageNode)
    38          lisa.setXMLlang(langset, lang)
    39          tig = etree.SubElement(langset, "tig") # or ntig with termGrp inside
    40          term = etree.SubElement(tig, self.textNode)
    41          # probably not what we want:
    42          # lisa.setXMLspace(term, "preserve")
    43          term.text = text
    44          return langset
    45
    46 -    def getid(self):
    47          # The id attribute is optional
    48          return self.xmlelement.get("id") or self.source
    49
    50
    51 -class tbxfile(lisa.LISAfile):
    52      """Class representing a TBX file store."""
    53      UnitClass = tbxunit
    54      Name = _("TBX Glossary")
    55      Mimetypes  = ["application/x-tbx"]
    56      Extensions = ["tbx"]
    57      rootNode = "martif"
    58      bodyNode = "body"
    59      XMLskeleton = '''<?xml version="1.0"?>
    60  <!DOCTYPE martif PUBLIC "ISO 12200:1999A//DTD MARTIF core (DXFcdV04)//EN" "TBXcdv04.dtd">
    61  <martif type="TBX">
    62  <martifHeader>
    63  <fileDesc>
    64  <sourceDesc><p>Translate Toolkit</p></sourceDesc>
    65  </fileDesc>
    66  </martifHeader>
    67  <text><body></body></text>
    68  </martif>'''
    69
    70 -    def addheader(self):
    71          """Initialise headers with TBX specific things."""
    72          lisa.setXMLlang(self.document.getroot(), self.sourcelanguage)
    73