Skip to content

Commit

Permalink
Merge pull request #1307 from benoit-pierre/improve_gettext_hook
Browse files Browse the repository at this point in the history
improve gettext hook
  • Loading branch information
benoit-pierre authored May 14, 2021
2 parents 4e7a542 + 667d46a commit c4ad3f8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions plover_build_utils/pyqt.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@ def gettext(contents):
def repl(m):
gd = m.groupdict()
comment = '{ws}# i18n: Widget: “{widget}”'.format(**gd)
if gd['type']:
comment += ", {type}".format(type=gd['type'].lower())
field = gd['field']
if field:
field = ' '.join(
word.lower()
for word in re.split(r'([A-Z][a-z_0-9]+)', field)
if word
)
comment += ", {field}".format(field=field)
comment += '.'
gd['pre2'] = gd['pre2'] or ''
return '{comment}\n{ws}{pre1}{pre2}_('.format(comment=comment, **gd)
contents = re.sub((r'(?P<ws> *)(?P<pre1>.*?)(?P<pre2>\.set(?P<type>\w+)\()?'
contents = re.sub((r'(?P<ws> *)(?P<pre1>.*?)(?P<pre2>\.set(?P<field>\w+)\()?'
r'\b_translate\("(?P<widget>.*)",\s'), repl, contents)
assert re.search(r'\b_translate\(', contents) is None
return contents
Expand Down

0 comments on commit c4ad3f8

Please sign in to comment.