Skip to content

Commit

Permalink
Followup for 9ec2eb8
Browse files Browse the repository at this point in the history
  • Loading branch information
unho committed Aug 21, 2015
1 parent 9ec2eb8 commit db283af
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
12 changes: 11 additions & 1 deletion translate/storage/cpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,17 @@ def _insert_header(self, header):
pass

def removeduplicates(self, duplicatestyle="merge"):
"""make sure each msgid is unique ; merge comments etc from duplicates into original"""
"""Make sure each msgid is unique.
The value of duplicatestyle tells which action is performed to
deal with duplicate entries. Valid values are:
merge - Duplicate entries are merged together,
allow - Duplicate entries are kept as is,
keep - Same as allow,
msgctxt - A msgctxt is added to ensure duplicate entries
are different.
"""
# TODO: can we handle consecutive calls to removeduplicates()? What
# about files already containing msgctxt? - test
id_dict = {}
Expand Down
12 changes: 11 additions & 1 deletion translate/storage/fpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,17 @@ def parse(self, input, duplicatestyle="merge"):
self.removeduplicates(duplicatestyle=duplicatestyle)

def removeduplicates(self, duplicatestyle="merge"):
"""Make sure each msgid is unique ; merge comments etc from duplicates into original"""
"""Make sure each msgid is unique.
The value of duplicatestyle tells which action is performed to
deal with duplicate entries. Valid values are:
merge - Duplicate entries are merged together,
allow - Duplicate entries are kept as is,
keep - Same as allow,
msgctxt - A msgctxt is added to ensure duplicate entries
are different.
"""
# TODO: can we handle consecutive calls to removeduplicates()? What
# about files already containing msgctxt? - test
id_dict = {}
Expand Down
2 changes: 1 addition & 1 deletion translate/storage/pocommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class pofile(poheader.poheader, base.TranslationStore):
# We don't want windows line endings on Windows:
_binary = True

def __init__(self, inputfile=None, encoding=None, duplicatestyle=None):
def __init__(self, inputfile=None, encoding=None, duplicatestyle="merge"):
super(pofile, self).__init__(unitclass=self.UnitClass)
self.units = []
self.filename = ''
Expand Down
13 changes: 11 additions & 2 deletions translate/storage/pypo.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,17 @@ def parse(self, input, duplicatestyle="merge"):
self.removeduplicates(duplicatestyle=duplicatestyle)

def removeduplicates(self, duplicatestyle="merge"):
"""Make sure each msgid is unique ; merge comments etc from
duplicates into original"""
"""Make sure each msgid is unique.
The value of duplicatestyle tells which action is performed to
deal with duplicate entries. Valid values are:
merge - Duplicate entries are merged together,
allow - Duplicate entries are kept as is,
keep - Same as allow,
msgctxt - A msgctxt is added to ensure duplicate entries
are different.
"""
# TODO: can we handle consecutive calls to removeduplicates()? What
# about files already containing msgctxt? - test
id_dict = {}
Expand Down
4 changes: 4 additions & 0 deletions translate/storage/test_cpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def test_merge_duplicates_msgctxt(self):
"""checks that merging duplicates works for msgctxt"""
posource = '#: source1\nmsgid "test me"\nmsgstr ""\n\n#: source2\nmsgid "test me"\nmsgstr ""\n'
pofile = self.poparse(posource, duplicatestyle="allow")
assert len(pofile.units) == 2
pofile.removeduplicates("msgctxt")
print(pofile)
assert len(pofile.units) == 2
Expand All @@ -111,6 +112,7 @@ def test_merge_blanks(self):
"""checks that merging adds msgid_comments to blanks"""
posource = '#: source1\nmsgid ""\nmsgstr ""\n\n#: source2\nmsgid ""\nmsgstr ""\n'
pofile = self.poparse(posource, duplicatestyle="allow")
assert len(pofile.units) == 2
pofile.removeduplicates("merge")
assert len(pofile.units) == 2
print(pofile.units[0].msgidcomments)
Expand All @@ -123,6 +125,7 @@ def test_msgid_comment(self):
"""checks that when adding msgid_comments we place them on a newline"""
posource = '#: source0\nmsgid "Same"\nmsgstr ""\n\n#: source1\nmsgid "Same"\nmsgstr ""\n'
pofile = self.poparse(posource, duplicatestyle="allow")
assert len(pofile.units) == 2
pofile.removeduplicates("msgid_comment")
assert len(pofile.units) == 2
assert po.unquotefrompo(pofile.units[0].msgidcomments) == "_: source0\n"
Expand All @@ -137,6 +140,7 @@ def test_keep_blanks(self):
"""checks that keeping keeps blanks and doesn't add msgid_comments"""
posource = '#: source1\nmsgid ""\nmsgstr ""\n\n#: source2\nmsgid ""\nmsgstr ""\n'
pofile = self.poparse(posource, duplicatestyle="allow")
assert len(pofile.units) == 2
pofile.removeduplicates("keep")
assert len(pofile.units) == 2
# check we don't add msgidcomments
Expand Down
2 changes: 2 additions & 0 deletions translate/storage/test_pypo.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ def test_merge_duplicates_msgctxt(self):
"""checks that merging duplicates works for msgctxt"""
posource = '#: source1\nmsgid "test me"\nmsgstr ""\n\n#: source2\nmsgid "test me"\nmsgstr ""\n'
pofile = self.poparse(posource, duplicatestyle="allow")
assert len(pofile.units) == 2
pofile.removeduplicates("msgctxt")
print(pofile)
assert len(pofile.units) == 2
Expand All @@ -245,6 +246,7 @@ def test_merge_blanks(self):
"""checks that merging adds msgid_comments to blanks"""
posource = '#: source1\nmsgid ""\nmsgstr ""\n\n#: source2\nmsgid ""\nmsgstr ""\n'
pofile = self.poparse(posource, duplicatestyle="allow")
assert len(pofile.units) == 2
pofile.removeduplicates("merge")
assert len(pofile.units) == 2
print(pofile.units[0].msgidcomments)
Expand Down

0 comments on commit db283af

Please sign in to comment.