Skip to content

Instantly share code, notes, and snippets.

@dolph dolph/clean_po.py
Last active Aug 29, 2015

Embed
What would you like to do?
De-duplicate transifex *.po files.
"""
Adapted from https://bugs.launchpad.net/ironic/+bug/1298645/comments/2
"""
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:
continue
if not line.startswith(matchee):
tmp_file.write(line)
else:
match_yet = True
shutil.move(tmp_file.name, path)
affected_paths.append(path)
return affected_paths
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='De-duplicate *.po files.')
parser.add_argument('locale_dir')
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.