Skip to content

Commit

Permalink
Merge pull request #4607 from rmol/fix-list-translators
Browse files Browse the repository at this point in the history
Fix i18n_tool's list-translators function
  • Loading branch information
zenmonkeykstop authored Jul 25, 2019
2 parents 0dec74f + fd5a27f commit a17525b
Showing 1 changed file with 30 additions and 35 deletions.
65 changes: 30 additions & 35 deletions securedrop/i18n_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,20 +284,20 @@ def add(p):
if updated:
self.upstream_commit(args, code)

def translators(self, args, path, range):
def translators(self, args, path, commit_range):
"""
Return the set of people who've modified a file in Weblate.
Extracts all the authors of translation changes to the given
path in the given range. Translation changes are identified by
the presence of "Translated using Weblate" in the commit
message.
path in the given commit range. Translation changes are
identified by the presence of "Translated using Weblate" in
the commit message.
"""
translation_re = re.compile('Translated using Weblate')

path_changes = git(
'--no-pager', '-C', args.root,
'log', '--format=%aN\x1e%s', range, '--', path,
'log', '--format=%aN\x1e%s', commit_range, '--', path,
_encoding='utf-8'
)
path_changes = u"{}".format(path_changes)
Expand All @@ -312,15 +312,11 @@ def upstream_commit(self, args, code):
authors = set()
diffs = u"{}".format(git('--no-pager', '-C', args.root, 'diff', '--name-only', '--cached'))

# This change will need to be checked in the next translation
# cycle after 0.13.0, to ensure that only recent commits are
# being picked up here.
update_re = re.compile(r'(?:copied from| revision:) (\w+)')

for path in sorted(diffs.strip().split('\n')):
previous_message = u"{}".format(git(
'--no-pager', '-C', args.root, 'log', '-n', '1', path,
_encoding='utf-8'))
update_re = re.compile(r'(?:updated from| revision:) (\w+)')
m = update_re.search(previous_message)
if m:
origin = m.group(1)
Expand Down Expand Up @@ -395,39 +391,38 @@ def set_list_translators_parser(self, subps):
parser.add_argument(
'--all',
action="store_true",
help="List everyone who's ever contributed."
help=(
"List everyone who's ever contributed, instead of just since the last "
"sync from Weblate."
)
)
parser.set_defaults(func=self.list_translators)

def get_last_sync(self):
commits = git('--no-pager', 'log', '--format=%h:%s', 'i18n/i18n', _encoding='utf-8')
for commit in commits:
commit_hash, msg = commit.split(':', 1)
if msg.startswith("l10n: sync "):
return commit_hash
return ""

def list_translators(self, args):
self.ensure_i18n_remote(args)
codes = list(I18NTool.SUPPORTED_LANGUAGES.keys())
path_templates = [
"install_files/ansible-base/roles/tails-config/templates/{}.po",
"securedrop/translations/{}/LC_MESSAGES/messages.po",
]
update_re = re.compile(r'(?:copied from| revision:) (\w+)')
for code in sorted(codes):
app_template = "securedrop/translations/{}/LC_MESSAGES/messages.po"
desktop_template = "install_files/ansible-base/roles/tails-config/templates/{}.po"
last_sync = self.get_last_sync()
for code, info in sorted(I18NTool.SUPPORTED_LANGUAGES.items()):
translators = set([])
info = I18NTool.SUPPORTED_LANGUAGES[code]
paths = [os.path.join(args.root, t.format(code)) for t in path_templates]
paths = [
app_template.format(code),
desktop_template.format(info["desktop"]),
]
for path in paths:
if not os.path.exists(path):
print("Skipping non-existent .po file: {}".format(path), file=sys.stderr)
continue
try:
range = "i18n/i18n"
if not args.all:
previous_message = u"{}".format(git(
'--no-pager', '-C', args.root, 'log', '-n', '1', path,
_encoding='utf-8'))
m = update_re.search(previous_message)
if m:
origin = m.group(1)
else:
origin = ''
range = '{}..i18n/i18n'.format(origin)
t = self.translators(args, path, range)
commit_range = "i18n/i18n"
if last_sync and not args.all:
commit_range = '{}..{}'.format(last_sync, commit_range)
t = self.translators(args, path, commit_range)
translators.update(t)
except Exception as e:
print("Could not check git history of {}: {}".format(path, e), file=sys.stderr)
Expand Down

0 comments on commit a17525b

Please sign in to comment.