| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
| 3 # | 3 # |
| 4 # Copyright 2005-2009 Zuza Software Foundation | 4 # Copyright 2005-2009 Zuza Software Foundation |
| 5 # | 5 # |
| 6 # This file is part of the Translate Toolkit. | 6 # This file is part of the Translate Toolkit. |
| 7 # | 7 # |
| 8 # This program is free software; you can redistribute it and/or modify | 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 | 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 | 10 # the Free Software Foundation; either version 2 of the License, or |
| 11 # (at your option) any later version. | 11 # (at your option) any later version. |
| 12 # | 12 # |
| 13 # This program is distributed in the hope that it will be useful, | 13 # This program is distributed in the hope that it will be useful, |
| 14 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 # GNU General Public License for more details. | 16 # GNU General Public License for more details. |
| 17 # | 17 # |
| 18 # You should have received a copy of the GNU General Public License | 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/>. | 19 # along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 20 | 20 |
| 21 """Module for handling XLIFF files for translation. | 21 """Module for handling XLIFF files for translation. |
| 22 | 22 |
| 23 The official recommendation is to use the extention .xlf for XLIFF files. | 23 The official recommendation is to use the extention .xlf for XLIFF files. |
| 24 """ | 24 """ |
| 25 | 25 |
| 26 from lxml import etree | 26 from lxml import etree |
| 27 | 27 |
| 28 from translate.misc.multistring import multistring | 28 from translate.misc.multistring import multistring |
| 29 from translate.misc.xml_helpers import * | 29 from translate.misc.xml_helpers import * |
| 30 from translate.storage import base, lisa | 30 from translate.storage import base, lisa |
| 31 from translate.storage.lisa import getXMLspace | 31 from translate.storage.lisa import getXMLspace |
| 32 from translate.storage.placeables.lisa import xml_to_strelem, strelem_to_xml | 32 from translate.storage.placeables.lisa import xml_to_strelem, strelem_to_xml |
| 33 | 33 |
| 34 # TODO: handle translation types | 34 # TODO: handle translation types |
| 35 | 35 |
| 36 class xliffunit(lisa.LISAunit): | 36 class xliffunit(lisa.LISAunit): |
| 37 """A single term in the xliff file.""" | 37 """A single term in the xliff file.""" |
| 38 | 38 |
| 39 rootNode = "trans-unit" | 39 rootNode = "trans-unit" |
| 40 languageNode = "source" | 40 languageNode = "source" |
| 41 textNode = "" | 41 textNode = "" |
| 42 namespace = 'urn:oasis:names:tc:xliff:document:1.1' | 42 namespace = 'urn:oasis:names:tc:xliff:document:1.1' |
| 43 | 43 |
| 44 _default_xml_space = "default" | 44 _default_xml_space = "default" |
| 45 | 45 |
| 46 #TODO: id and all the trans-unit level stuff | 46 #TODO: id and all the trans-unit level stuff |
| 47 | 47 |
| 48 def __init__(self, source, empty=False, **kwargs): | 48 def __init__(self, source, empty=False, **kwargs): |
| 49 """Override the constructor to set xml:space="preserve".""" | 49 """Override the constructor to set xml:space="preserve".""" |
| 50 if empty: | 50 if empty: |
| (...skipping 182 matching lines...) Show 10 above Show 10 below |
| 233 errordict = {} | 233 errordict = {} |
| 234 for note in notelist: | 234 for note in notelist: |
| 235 errorname, errortext = note.split(': ') | 235 errorname, errortext = note.split(': ') |
| 236 errordict[errorname] = errortext | 236 errordict[errorname] = errortext |
| 237 return errordict | 237 return errordict |
| 238 | 238 |
| 239 def isapproved(self): | 239 def isapproved(self): |
| 240 """States whether this unit is approved.""" | 240 """States whether this unit is approved.""" |
| 241 return self.xmlelement.get("approved") == "yes" | 241 return self.xmlelement.get("approved") == "yes" |
| 242 | 242 |
| 243 def markapproved(self, value=True): | 243 def markapproved(self, value=True): |
| 244 """Mark this unit as approved.""" | 244 """Mark this unit as approved.""" |
| 245 if value: | 245 if value: |
| 246 self.xmlelement.set("approved", "yes") | 246 self.xmlelement.set("approved", "yes") |
| 247 elif self.isapproved(): | 247 elif self.isapproved(): |
| 248 self.xmlelement.set("approved", "no") | 248 self.xmlelement.set("approved", "no") |
| 249 | 249 |
| 250 def isreview(self): | 250 def isreview(self): |
| 251 """States whether this unit needs to be reviewed""" | 251 """States whether this unit needs to be reviewed""" |
| 252 targetnode = self.getlanguageNode(lang=None, index=1) | 252 targetnode = self.getlanguageNode(lang=None, index=1) |
| 253 return not targetnode is None and \ | 253 return not targetnode is None and \ |
| 254 "needs-review" in targetnode.get("state", "") | 254 "needs-review" in targetnode.get("state", "") |
| 255 | 255 |
| 256 def markreviewneeded(self, needsreview=True, explanation=None): | 256 def markreviewneeded(self, needsreview=True, explanation=None): |
| 257 """Marks the unit to indicate whether it needs review. Adds an optional
explanation as a note.""" | 257 """Marks the unit to indicate whether it needs review. Adds an optional
explanation as a note.""" |
| 258 targetnode = self.getlanguageNode(lang=None, index=1) | 258 targetnode = self.getlanguageNode(lang=None, index=1) |
| 259 if not targetnode is None: | 259 if not targetnode is None: |
| 260 if needsreview: | 260 if needsreview: |
| 261 targetnode.set("state", "needs-review-translation") | 261 targetnode.set("state", "needs-review-translation") |
| 262 if explanation: | 262 if explanation: |
| 263 self.addnote(explanation, origin="translator") | 263 self.addnote(explanation, origin="translator") |
| 264 else: | 264 else: |
| 265 del targetnode.attrib["state"] | 265 del targetnode.attrib["state"] |
| 266 | 266 |
| 267 def isfuzzy(self): | 267 def isfuzzy(self): |
| 268 # targetnode = self.getlanguageNode(lang=None, index=1) | 268 # targetnode = self.getlanguageNode(lang=None, index=1) |
| 269 # return not targetnode is None and \ | 269 # return not targetnode is None and \ |
| 270 # (targetnode.get("state-qualifier") == "fuzzy-match" or \ | 270 # (targetnode.get("state-qualifier") == "fuzzy-match" or \ |
| 271 # targetnode.get("state") == "needs-review-translation") | 271 # targetnode.get("state") == "needs-review-translation") |
| 272 return not self.isapproved() | 272 return not self.isapproved() |
| 273 | 273 |
| 274 def markfuzzy(self, value=True): | 274 def markfuzzy(self, value=True): |
| 275 if value: | 275 if value: |
| 276 self.markapproved(False) | 276 self.markapproved(False) |
| 277 else: | 277 else: |
| 278 self.markapproved(True) | 278 self.markapproved(True) |
| 279 targetnode = self.getlanguageNode(lang=None, index=1) | 279 targetnode = self.getlanguageNode(lang=None, index=1) |
| 280 if not targetnode is None: | 280 if not targetnode is None: |
| 281 if value: | 281 if value: |
| 282 targetnode.set("state", "needs-review-translation") | 282 targetnode.set("state", "needs-review-translation") |
error: old chunk mismatch |
| OLD | NEW |