unique-messages.py 937 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env python
  2. import os
  3. import sys
  4. def unique_messages():
  5. basedir = None
  6. if os.path.isdir(os.path.join('conf', 'locale')):
  7. basedir = os.path.abspath(os.path.join('conf', 'locale'))
  8. elif os.path.isdir('locale'):
  9. basedir = os.path.abspath('locale')
  10. else:
  11. print("This script should be run from the Django Git tree or your project or app tree.")
  12. sys.exit(1)
  13. for (dirpath, dirnames, filenames) in os.walk(basedir):
  14. for f in filenames:
  15. if f.endswith('.po'):
  16. sys.stderr.write('processing file %s in %s\n' % (f, dirpath))
  17. pf = os.path.splitext(os.path.join(dirpath, f))[0]
  18. cmd = 'msguniq "%s.po"' % pf
  19. stdout = os.popen(cmd)
  20. msg = stdout.read()
  21. with open('%s.po' % pf, 'w') as fp:
  22. fp.write(msg)
  23. if __name__ == "__main__":
  24. unique_messages()