Skip to content

Commit

Permalink
Improve po2tmx for cPO and fPO
Browse files Browse the repository at this point in the history
Slight changes to code and tests to ensure that the extraction works for other
PO parsers.
  • Loading branch information
dwaynebailey committed Dec 2, 2013
1 parent 2cdf3e2 commit d29002e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions translate/convert/po2tmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@

class po2tmx:

def cleancomments(self, comments):
def cleancomments(self, comments, comment_type=None):
"""Removes the comment marks from the PO strings."""
# FIXME this is a bit hacky, needs some fixes in the PO classes
for index, comment in enumerate(comments):
if comment.startswith("#"):
comments[index] = comment[1:].rstrip()
if comment_type is None:
comments[index] = comment[1:].rstrip()
else:
comments[index] = comment[2:].strip()

return ''.join(comments)

Expand All @@ -53,8 +57,8 @@ def convertfiles(self, inputfile, tmxfile, sourcelanguage='en',
translation = inunit.target

commenttext = {
'source': self.cleancomments(inunit.sourcecomments),
'type': self.cleancomments(inunit.typecomments),
'source': self.cleancomments(inunit.sourcecomments, "source"),
'type': self.cleancomments(inunit.typecomments, "type"),
'others': self.cleancomments(inunit.othercomments),
}.get(comment, None)

Expand Down
4 changes: 2 additions & 2 deletions translate/convert/test_po2tmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def test_sourcecomments(self):
tmx = self.po2tmx(minipo, comment='source')
print str(tmx)
unit = tmx.findunits(u"Bézier curve")
assert unit[0].getnotes() == u": ../PuzzleFourSided.h:45"
assert unit[0].getnotes() == u"../PuzzleFourSided.h:45"

def test_typecomments(self):
"""Tests that others comments are imported."""
Expand All @@ -186,7 +186,7 @@ def test_typecomments(self):
tmx = self.po2tmx(minipo, comment='type')
print str(tmx)
unit = tmx.findunits(u"Bézier curve")
assert unit[0].getnotes() == u", csharp-format"
assert unit[0].getnotes() == u"csharp-format"

class TestPO2TMXCommand(test_convert.TestConvertCommand, TestPO2TMX):
"""Tests running actual po2tmx commands on files"""
Expand Down

0 comments on commit d29002e

Please sign in to comment.