Skip to content

Instantly share code, notes, and snippets.

@dolph dolph/
Last active Aug 29, 2015

What would you like to do?
De-duplicate transifex *.po files.
Adapted from
import argparse
import os
import shutil
import tempfile
def patch_po_files(input_dir_name):
affected_paths = []
for root, dirs, files in os.walk(input_dir_name):
for file_name in files:
path = os.path.join(root, file_name)
with open(path, "r") as input_file:
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
matchee = '#~ msg'
match_yet = False
for line in input_file:
if match_yet:
if not line.startswith(matchee):
match_yet = True
shutil.move(, path)
return affected_paths
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='De-duplicate *.po files.')
args = parser.parse_args()
for path in patch_po_files(args.locale_dir):
print('Patched: %s' % path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.