2015-04-16 01:11:25 -04:00
|
|
|
#!/usr/bin/env python
|
2015-03-31 18:41:37 -04:00
|
|
|
|
|
|
|
# A simple script that adds all authors from transifex, which are
|
|
|
|
# listed in comments at the beginning of the file, to the
|
|
|
|
# 'translator-credits' translations - where launchpad added them
|
|
|
|
# and which are shown in stk.
|
2015-04-01 07:24:02 -04:00
|
|
|
#
|
|
|
|
# Usage: update_po_authors.py PATH_TO/LANGUAGE.po
|
|
|
|
#
|
|
|
|
# IMPORTANT note: this script must be run on a file downloaded
|
|
|
|
# from transifex, not on a file on which this script had
|
|
|
|
# been run before (otherwise the transifex authors would
|
|
|
|
# be added again and again)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
#
|
|
|
|
# Less important note: The specified file is overwritten without
|
|
|
|
# a backup! Make sure the git status is unmodified.
|
|
|
|
|
2015-03-31 18:41:37 -04:00
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if len(sys.argv)!=2:
|
|
|
|
print "Usage: getpo_authors.py PATH_TO_PO_FILE"
|
|
|
|
sys.exit(-1)
|
|
|
|
|
|
|
|
f = open(sys.argv[1], "r")
|
|
|
|
if not f:
|
|
|
|
print "Can not find", sys.argv[1]
|
|
|
|
exit
|
|
|
|
lines = f.readlines()
|
|
|
|
|
|
|
|
f.close()
|
|
|
|
|
2015-04-01 07:24:02 -04:00
|
|
|
new_authors = []
|
|
|
|
found = 0
|
2015-03-31 18:41:37 -04:00
|
|
|
|
|
|
|
# Find all authors with a simple finite state machine:
|
|
|
|
contributions = -1
|
|
|
|
line_count = 0
|
|
|
|
for i in lines:
|
|
|
|
line = i[:-1] # remove \n
|
|
|
|
if line=="# Translators:":
|
|
|
|
found = 1
|
2015-04-16 01:11:25 -04:00
|
|
|
elif found and line[:2]=="# " and line [:14]!="# FIRST AUTHOR":
|
2015-04-01 07:24:02 -04:00
|
|
|
new_authors.append(line[2:])
|
2015-03-31 18:41:37 -04:00
|
|
|
elif line[:5]=="msgid":
|
|
|
|
found = 0
|
|
|
|
elif line[:31]== "msgstr \"Launchpad Contributions":
|
|
|
|
contributions = line_count
|
|
|
|
line_count = line_count + 1
|
|
|
|
|
|
|
|
|
|
|
|
# Delete all email addresses - not sure if the authors
|
|
|
|
# would want them to be published
|
|
|
|
email=re.compile(" *<.*@.*\..*> *") # one @ and one dot at least
|
2015-04-01 07:24:02 -04:00
|
|
|
for i in range(len(new_authors)):
|
|
|
|
g = email.search(new_authors[i])
|
2015-03-31 18:41:37 -04:00
|
|
|
if g:
|
2015-04-01 07:24:02 -04:00
|
|
|
new_authors[i] = new_authors[i][:g.start()] \
|
|
|
|
+ new_authors[i][g.end():]
|
2015-03-31 18:41:37 -04:00
|
|
|
|
2015-04-01 07:24:02 -04:00
|
|
|
# Get the old authors from the translator-credits string:
|
|
|
|
if contributions>0:
|
|
|
|
# Ignore the first entry, which is "msgstr ...", and the
|
|
|
|
# last two characters, which are the '"\n'.
|
|
|
|
old_authors = lines[contributions][:-2].split("\\n")[1:]
|
|
|
|
for i in range(len(old_authors)):
|
|
|
|
old_authors[i] = old_authors[i].strip()
|
|
|
|
else:
|
|
|
|
old_authors=[]
|
|
|
|
|
|
|
|
all_authors = old_authors + new_authors;
|
|
|
|
all_authors = sorted(all_authors, key=lambda x: x.lower())
|
|
|
|
all_authors_string = reduce(lambda x,y: x+"\\n"+y, all_authors, "")
|
2015-10-15 18:46:59 -04:00
|
|
|
|
|
|
|
credits_line = "msgstr \"Launchpad Contributions:%s\"\n"%all_authors_string
|
2015-04-01 07:24:02 -04:00
|
|
|
# If no old authors exists, write a new entry:
|
2015-03-31 18:41:37 -04:00
|
|
|
if contributions==-1:
|
2015-04-01 07:24:02 -04:00
|
|
|
lines.append("\n")
|
|
|
|
lines.append("#: src/states_screens/credits.cpp:209\n")
|
|
|
|
lines.append("msgid \"translator-credits\"\n")
|
2015-10-15 18:46:59 -04:00
|
|
|
lines.append(credits_line)
|
2015-03-31 18:41:37 -04:00
|
|
|
else:
|
2015-10-15 18:46:59 -04:00
|
|
|
# Otherwise just replace the old contribution string
|
|
|
|
lines[contributions] = credits_line
|
2015-04-01 07:24:02 -04:00
|
|
|
|
2015-03-31 18:41:37 -04:00
|
|
|
|
2015-04-01 07:24:02 -04:00
|
|
|
# Overwrite old file
|
2015-03-31 18:41:37 -04:00
|
|
|
f = open(sys.argv[1], "w")
|
|
|
|
for i in lines:
|
|
|
|
f.write(i)
|
|
|
|
f.close()
|
|
|
|
|