Back to index

plone3  3.1.7
setcomment.py
Go to the documentation of this file.
00001 """
00002    Usage: setcomment.py <product> <comment>
00003 """
00004 
00005 import os, sys
00006 import getopt
00007 from utils import getPoFiles, getLongProductName
00008 
00009 from i18ndude import catalog
00010 
00011 
00012 def main():
00013     if len(sys.argv) < 2:
00014         print 'You have to specify the product.'
00015         sys.exit(1)
00016 
00017     product = getLongProductName(sys.argv[1])
00018 
00019     os.chdir('..')
00020     os.chdir('i18n')
00021 
00022     poFiles = getPoFiles(product, all=True)
00023     if poFiles == []:
00024         print 'No po-files were found for the given product.'
00025         sys.exit(2)
00026 
00027     for poFile in poFiles:
00028         try:
00029             po_ctl = catalog.MessageCatalog(filename=poFile)
00030         except IOError, e:
00031             print >> sys.stderr, 'I/O Error: %s' % e
00032 
00033         try:
00034             language = po_ctl.commentary_header[0].split('to ')[1:][0]
00035             po_ctl.commentary_header[0] = 'Translation of '+product+'.pot to '+language
00036         except IndexError:
00037             print poFile
00038 
00039         file = open(poFile+'-new', 'w')
00040         writer = catalog.POWriter(file, po_ctl)
00041         writer.write(sort=False)
00042 
00043 if __name__ == '__main__':
00044     main()