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

Source Code for Module translate.storage.placeables.base

  1  #!/usr/bin/env python 
  2  # -*- coding: utf-8 -*- 
  3  # 
  4  # Copyright 2008-2009 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  """ 
 22  Contains base placeable classes with names based on XLIFF placeables. See the 
 23  XLIFF standard for more information about what the names mean. 
 24  """ 
 25   
 26  from translate.storage.placeables.interfaces import * 
 27  from translate.storage.placeables.strelem import StringElem 
 28   
 29   
 30  __all__ = ['Bpt', 'Ept', 'Ph', 'It', 'G', 'Bx', 'Ex', 'X', 'Sub', 'to_base_placeables'] 
 31   
 32   
 33  # Basic placeable types. 
34 -class Bpt(MaskingPlaceable, PairedDelimiter):
35 has_content = True
36 37
38 -class Ept(MaskingPlaceable, PairedDelimiter):
39 has_content = True
40 41
42 -class Ph(MaskingPlaceable):
43 has_content = True 44 istranslatable = False
45 46
47 -class It(MaskingPlaceable, Delimiter):
48 has_content = True
49 50
51 -class G(ReplacementPlaceable):
52 has_content = True
53 54
55 -class Bx(ReplacementPlaceable, PairedDelimiter):
56 has_content = False 57 istranslatable = False 58
59 - def __init__(self, id=None, xid=None, **kwargs):
60 # kwargs is ignored 61 ReplacementPlaceable.__init__(self, id=id, xid=xid, **kwargs)
62 63
64 -class Ex(ReplacementPlaceable, PairedDelimiter):
65 has_content = False 66 istranslatable = False 67
68 - def __init__(self, id=None, xid=None, **kwargs):
69 # kwargs is ignored 70 ReplacementPlaceable.__init__(self, id=id, xid=xid, **kwargs)
71 72
73 -class X(ReplacementPlaceable, Delimiter):
74 has_content = False 75 iseditable = False 76 isfragile = True 77 istranslatable = False 78
79 - def __init__(self, id=None, xid=None, **kwargs):
80 ReplacementPlaceable.__init__(self, id=id, xid=xid, **kwargs)
81 82
83 -class Sub(SubflowPlaceable):
84 has_content = True
85 86
87 -def to_base_placeables(tree):
88 if not isinstance(tree, StringElem): 89 return tree 90 91 base_class = [klass for klass in tree.__class__.__bases__ \ 92 if klass in [Bpt, Ept, Ph, It, G, Bx, Ex, X, Sub]] 93 94 if not base_class: 95 base_class = tree.__class__ 96 else: 97 base_class = base_class[0] 98 99 newtree = base_class() 100 newtree.id = tree.id 101 newtree.rid = tree.rid 102 newtree.xid = tree.xid 103 newtree.sub = [] 104 105 for subtree in tree.sub: 106 newtree.sub.append(to_base_placeables(subtree)) 107 108 return newtree
109