Skip to content
Snippets Groups Projects
pre-translate-po 982 B
#!/usr/bin/python3

import polib
import re
import sys

def main (f):
    po = polib.pofile(f)

    for entry in po:
        if (re.fullmatch(r'-[-a-z0-9[\]]+', entry.msgid)) \
           or re.fullmatch(r'((linkgit:)?git-[-a-z0-9[\]]+(\[1\]|\(1\))(\n| )?)+', entry.msgid) \
           or re.fullmatch(r'`[a-zA-Z-_]+`|(user|transfer|submodule|stash|status|splitIndex|showbranch|sendemail|repack|remote|receive|push|mergetool|mailinfo|log|interactive|instaweb|i18n|help|gui|gitweb|fastimport|format|fetch|difftool|credential|commit|column|core|branch|diff|apply|color)\.[a-zA-Z_.]+', entry.msgid):
            entry.msgstr = entry.msgid
            entry.flags.append("ignore-translated")
            flags = set(entry.flags)
            entry.flags = list(flags)
            if 'fuzzy' in entry.flags:
                entry.flags.remove('fuzzy')
                entry.previous_msgid = None
    po.save(f)

if __name__ == '__main__':
    if len(sys.argv)>1:
        main(sys.argv[1])