Skip to content

Instantly share code, notes, and snippets.

@maxpeterson
Created February 1, 2019 11:38
Show Gist options
  • Save maxpeterson/2ce12c2d43f7a68c4ffa21584c0de7c3 to your computer and use it in GitHub Desktop.
Save maxpeterson/2ce12c2d43f7a68c4ffa21584c0de7c3 to your computer and use it in GitHub Desktop.

Revisions

  1. maxpeterson created this gist Feb 1, 2019.
    33 changes: 33 additions & 0 deletions fake_translate.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    #!/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])