Created
February 1, 2019 11:38
-
-
Save maxpeterson/2ce12c2d43f7a68c4ffa21584c0de7c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- python -*- | |
# Usage: python fake_translate.py inputfile.po outputfile.po | |
import re | |
import sys | |
import polib | |
# handle leading whitespace | |
start = re.compile('^(\s*)') | |
end = re.compile('(\s*)$') | |
def fake(msgid): | |
"""Generate a fake translation for the msgid""" | |
return end.sub('**\g<1>', start.sub('\g<1>**', msgid)) | |
po = polib.pofile(sys.argv[1]) | |
for entry in po: | |
if entry.msgid_plural: | |
entry.msgstr_plural = { | |
0: fake(entry.msgid), | |
1: fake(entry.msgid_plural), | |
} | |
elif entry.msgid: | |
entry.msgstr = fake(entry.msgid) | |
po.save(sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment