Skip to content

Instantly share code, notes, and snippets.

@maxpeterson
Created February 1, 2019 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxpeterson/2ce12c2d43f7a68c4ffa21584c0de7c3 to your computer and use it in GitHub Desktop.
Save maxpeterson/2ce12c2d43f7a68c4ffa21584c0de7c3 to your computer and use it in GitHub Desktop.
#!/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