Skip to content

Commit

Permalink
Fix ContentState issue when pushing plural to server, apply the rules…
Browse files Browse the repository at this point in the history
… from maven client
  • Loading branch information
jamesni committed Apr 19, 2012
1 parent 00eef9f commit 7021d86
Showing 1 changed file with 42 additions and 17 deletions.
59 changes: 42 additions & 17 deletions zanataclient/publicanutil.py
Expand Up @@ -88,6 +88,44 @@ def create_txtflow(self, pofile):
textflows.append(textflow)
return textflows

def check_empty(self, contents):
for string in contents:
if string != u'':
return False
return True

def check_nonempty(self, contents):
for string in contents:
if string == u'':
return False
return True

def get_contentstate(self, entry):
fuzzy = False
contents = []

if "fuzzy" in entry.flags:
fuzzy = True

if entry.msgid_plural:
keys = entry.msgstr_plural.keys()
keys.sort()
for key in keys:
contents.append(entry.msgstr_plural[key])
else:
contents.append(entry.msgstr)

if self.check_empty(contents):
fuzzy = False;

if fuzzy:
return "NeedReview"

if self.check_nonempty(contents):
return "Approved"
else:
return "New"

def create_txtflowtarget(self, pofile):
"""
Convert the content of the po file to a list of textflowtarget.
Expand All @@ -96,7 +134,7 @@ def create_txtflowtarget(self, pofile):
obs_list=pofile.obsolete_entries()
textflowtargets = []
content = ""

for entry in pofile:
if entry in obs_list:
continue
Expand All @@ -111,20 +149,7 @@ def create_txtflowtarget(self, pofile):
textflowId = m.hexdigest()
translator_comment = entry.tcomment

#need judge for fuzzy state
if "fuzzy" in entry.flags:
state = "NeedReview"

if entry.msgid_plural:
if "" in entry.msgstr_plural.values():
state = "New"
else:
state = "Approved"
else:
if entry.msgstr:
state = "Approved"
else:
state = "New"
state = self.get_contentstate(entry)

#create extensions
extensions = [{"object-type":"comment","value":translator_comment,"space":"preserve"}]
Expand All @@ -139,9 +164,9 @@ def create_txtflowtarget(self, pofile):
else:
content = entry.msgstr
textflowtarget = {'resId': textflowId, 'state': state, 'content':content,'extensions':extensions}

textflowtargets.append(textflowtarget)

return textflowtargets

def validate_content_type(self, content_type, object_type):
Expand Down

0 comments on commit 7021d86

Please sign in to comment.