Mercurial > babel > mirror
comparison babel/messages/frontend.py @ 600:e61e27d9347d trunk
"init" command support "--width" option (#284)
author | fschwarz |
---|---|
date | Mon, 20 Aug 2012 20:07:27 +0000 |
parents | 99c48a6ca1d6 |
children | 3eeaadb290be |
comparison
equal
deleted
inserted
replaced
599:33c8c68b96c7 | 600:e61e27d9347d |
---|---|
400 ('output-file=', 'o', | 400 ('output-file=', 'o', |
401 "name of the output file (default " | 401 "name of the output file (default " |
402 "'<output_dir>/<locale>/LC_MESSAGES/<domain>.po')"), | 402 "'<output_dir>/<locale>/LC_MESSAGES/<domain>.po')"), |
403 ('locale=', 'l', | 403 ('locale=', 'l', |
404 'locale for the new localized catalog'), | 404 'locale for the new localized catalog'), |
405 ('width=', 'w', | |
406 'set output line width (default 76)'), | |
405 ('no-wrap', None, | 407 ('no-wrap', None, |
406 'do not break long message lines, longer than the output line width, ' | 408 'do not break long message lines, longer than the output line width, ' |
407 'into several lines'), | 409 'into several lines'), |
408 ] | 410 ] |
409 boolean_options = ['no-wrap'] | 411 boolean_options = ['no-wrap'] |
435 self.output_file = os.path.join(self.output_dir, self.locale, | 437 self.output_file = os.path.join(self.output_dir, self.locale, |
436 'LC_MESSAGES', self.domain + '.po') | 438 'LC_MESSAGES', self.domain + '.po') |
437 | 439 |
438 if not os.path.exists(os.path.dirname(self.output_file)): | 440 if not os.path.exists(os.path.dirname(self.output_file)): |
439 os.makedirs(os.path.dirname(self.output_file)) | 441 os.makedirs(os.path.dirname(self.output_file)) |
440 if not self.no_wrap: | 442 if not self.no_wrap and not self.width: |
441 self.width = 76 | 443 self.width = 76 |
444 elif self.width is not None: | |
445 self.width = int(self.width) | |
442 | 446 |
443 def run(self): | 447 def run(self): |
444 log.info('creating catalog %r based on %r', self.output_file, | 448 log.info('creating catalog %r based on %r', self.output_file, |
445 self.input_file) | 449 self.input_file) |
446 | 450 |
957 help="name of the output file (default " | 961 help="name of the output file (default " |
958 "'<output_dir>/<locale>/LC_MESSAGES/" | 962 "'<output_dir>/<locale>/LC_MESSAGES/" |
959 "<domain>.po')") | 963 "<domain>.po')") |
960 parser.add_option('--locale', '-l', dest='locale', metavar='LOCALE', | 964 parser.add_option('--locale', '-l', dest='locale', metavar='LOCALE', |
961 help='locale for the new localized catalog') | 965 help='locale for the new localized catalog') |
966 parser.add_option('-w', '--width', dest='width', type='int', | |
967 help="set output line width (default 76)") | |
962 parser.add_option('--no-wrap', dest='no_wrap', action='store_true', | 968 parser.add_option('--no-wrap', dest='no_wrap', action='store_true', |
963 help='do not break long message lines, longer than ' | 969 help='do not break long message lines, longer than ' |
964 'the output line width, into several lines') | 970 'the output line width, into several lines') |
965 | 971 |
966 parser.set_defaults(domain='messages') | 972 parser.set_defaults(domain='messages') |
983 options.output_file = os.path.join(options.output_dir, | 989 options.output_file = os.path.join(options.output_dir, |
984 options.locale, 'LC_MESSAGES', | 990 options.locale, 'LC_MESSAGES', |
985 options.domain + '.po') | 991 options.domain + '.po') |
986 if not os.path.exists(os.path.dirname(options.output_file)): | 992 if not os.path.exists(os.path.dirname(options.output_file)): |
987 os.makedirs(os.path.dirname(options.output_file)) | 993 os.makedirs(os.path.dirname(options.output_file)) |
988 width = 76 | 994 if options.width and options.no_wrap: |
989 if options.no_wrap: | 995 parser.error("'--no-wrap' and '--width' are mutually exclusive.") |
990 width = None | 996 elif not options.width and not options.no_wrap: |
997 options.width = 76 | |
991 | 998 |
992 infile = open(options.input_file, 'r') | 999 infile = open(options.input_file, 'r') |
993 try: | 1000 try: |
994 # Although reading from the catalog template, read_po must be fed | 1001 # Although reading from the catalog template, read_po must be fed |
995 # the locale in order to correctly calculate plurals | 1002 # the locale in order to correctly calculate plurals |
1003 self.log.info('creating catalog %r based on %r', options.output_file, | 1010 self.log.info('creating catalog %r based on %r', options.output_file, |
1004 options.input_file) | 1011 options.input_file) |
1005 | 1012 |
1006 outfile = open(options.output_file, 'w') | 1013 outfile = open(options.output_file, 'w') |
1007 try: | 1014 try: |
1008 write_po(outfile, catalog, width=width) | 1015 write_po(outfile, catalog, width=options.width) |
1009 finally: | 1016 finally: |
1010 outfile.close() | 1017 outfile.close() |
1011 | 1018 |
1012 def update(self, argv): | 1019 def update(self, argv): |
1013 """Subcommand for updating existing message catalogs from a template. | 1020 """Subcommand for updating existing message catalogs from a template. |