comparison babel/messages/frontend.py @ 202:d3c272492053

Added `--no-fuzzy-matching` to the frontends and also `--previous` which adds the old msgid's as comments. The latest closes #31.
author palgarvio
date Tue, 03 Jul 2007 17:55:34 +0000
parents e15b7165ced5
children 3be04778442f
comparison
equal deleted inserted replaced
201:10e8d072e2d1 202:d3c272492053
453 "name of the output file (default " 453 "name of the output file (default "
454 "'<output_dir>/<locale>/LC_MESSAGES/<domain>.po')"), 454 "'<output_dir>/<locale>/LC_MESSAGES/<domain>.po')"),
455 ('locale=', 'l', 455 ('locale=', 'l',
456 'locale of the catalog to compile'), 456 'locale of the catalog to compile'),
457 ('ignore-obsolete=', None, 457 ('ignore-obsolete=', None,
458 'whether to omit obsolete messages from the output') 458 'whether to omit obsolete messages from the output'),
459 ('no-fuzzy-matching', 'N',
460 'do not use fuzzy matching'),
461 ('previous', None,
462 'keep previous msgids of translated messages')
459 ] 463 ]
460 boolean_options = ['ignore_obsolete'] 464 boolean_options = ['ignore_obsolete', 'no_fuzzy_matching', 'previous']
461 465
462 def initialize_options(self): 466 def initialize_options(self):
463 self.domain = 'messages' 467 self.domain = 'messages'
464 self.input_file = None 468 self.input_file = None
465 self.output_dir = None 469 self.output_dir = None
466 self.output_file = None 470 self.output_file = None
467 self.locale = None 471 self.locale = None
468 self.ignore_obsolete = False 472 self.ignore_obsolete = False
473 self.no_fuzzy_matching = False
474 self.previous = False
469 475
470 def finalize_options(self): 476 def finalize_options(self):
471 if not self.input_file: 477 if not self.input_file:
472 raise DistutilsOptionError('you must specify the input file') 478 raise DistutilsOptionError('you must specify the input file')
473 if not self.output_file and not self.output_dir: 479 if not self.output_file and not self.output_dir:
474 raise DistutilsOptionError('you must specify the output file or ' 480 raise DistutilsOptionError('you must specify the output file or '
475 'directory') 481 'directory')
476 if self.output_file and not self.locale: 482 if self.output_file and not self.locale:
477 raise DistutilsOptionError('you must specify the locale') 483 raise DistutilsOptionError('you must specify the locale')
484 if self.no_fuzzy_matching and self.previous:
485 self.previous = False
478 486
479 def run(self): 487 def run(self):
480 po_files = [] 488 po_files = []
481 if not self.output_file: 489 if not self.output_file:
482 if self.locale: 490 if self.locale:
511 try: 519 try:
512 catalog = read_po(infile, locale=locale, domain=domain) 520 catalog = read_po(infile, locale=locale, domain=domain)
513 finally: 521 finally:
514 infile.close() 522 infile.close()
515 523
516 catalog.update(template) 524 catalog.update(template, self.no_fuzzy_matching, self.previous)
517 525
518 tmpname = os.path.join(os.path.dirname(filename), 526 tmpname = os.path.join(os.path.dirname(filename),
519 tempfile.gettempprefix() + 527 tempfile.gettempprefix() +
520 os.path.basename(filename)) 528 os.path.basename(filename))
521 tmpfile = open(tmpname, 'w') 529 tmpfile = open(tmpname, 'w')
522 try: 530 try:
523 try: 531 try:
524 write_po(tmpfile, catalog, 532 write_po(tmpfile, catalog,
525 ignore_obsolete=self.ignore_obsolete) 533 ignore_obsolete=self.ignore_obsolete,
534 include_old_msgid=self.previous)
526 finally: 535 finally:
527 tmpfile.close() 536 tmpfile.close()
528 except: 537 except:
529 os.remove(tmpname) 538 os.remove(tmpname)
530 raise 539 raise
888 help='locale of the translations catalog') 897 help='locale of the translations catalog')
889 parser.add_option('--ignore-obsolete', dest='ignore_obsolete', 898 parser.add_option('--ignore-obsolete', dest='ignore_obsolete',
890 action='store_true', 899 action='store_true',
891 help='do not include obsolete messages in the output ' 900 help='do not include obsolete messages in the output '
892 '(default %default)'), 901 '(default %default)'),
893 902 parser.add_option('--no-fuzzy-matching', '-N', dest='no_fuzzy_matching',
894 parser.set_defaults(domain='messages', ignore_obsolete=False) 903 action='store_true',
904 help='do not use fuzzy matching (default %default)'),
905 parser.add_option('--previous', dest='previous', action='store_true',
906 help='keep previous msgids of translated messages '
907 '(default %default)'),
908
909 parser.set_defaults(domain='messages', ignore_obsolete=False,
910 no_fuzzy_matching=False, previous=False)
895 options, args = parser.parse_args(argv) 911 options, args = parser.parse_args(argv)
896 912
897 if not options.input_file: 913 if not options.input_file:
898 parser.error('you must specify the input file') 914 parser.error('you must specify the input file')
899 if not options.output_file and not options.output_dir: 915 if not options.output_file and not options.output_dir:
900 parser.error('you must specify the output file or directory') 916 parser.error('you must specify the output file or directory')
901 if options.output_file and not options.locale: 917 if options.output_file and not options.locale:
902 parser.error('you must specify the loicale') 918 parser.error('you must specify the loicale')
919 if options.no_fuzzy_matching and options.previous:
920 options.previous = False
903 921
904 po_files = [] 922 po_files = []
905 if not options.output_file: 923 if not options.output_file:
906 if options.locale: 924 if options.locale:
907 po_files.append((options.locale, 925 po_files.append((options.locale,
935 try: 953 try:
936 catalog = read_po(infile, locale=locale, domain=domain) 954 catalog = read_po(infile, locale=locale, domain=domain)
937 finally: 955 finally:
938 infile.close() 956 infile.close()
939 957
940 catalog.update(template) 958 catalog.update(template, options.no_fuzzy_matching,
941 959 options.previous)
942 catalog.update(template)
943 960
944 tmpname = os.path.join(os.path.dirname(filename), 961 tmpname = os.path.join(os.path.dirname(filename),
945 tempfile.gettempprefix() + 962 tempfile.gettempprefix() +
946 os.path.basename(filename)) 963 os.path.basename(filename))
947 tmpfile = open(tmpname, 'w') 964 tmpfile = open(tmpname, 'w')
948 try: 965 try:
949 try: 966 try:
950 write_po(tmpfile, catalog, 967 write_po(tmpfile, catalog,
951 ignore_obsolete=options.ignore_obsolete) 968 ignore_obsolete=options.ignore_obsolete,
969 include_old_msgid=options.previous)
952 finally: 970 finally:
953 tmpfile.close() 971 tmpfile.close()
954 except: 972 except:
955 os.remove(tmpname) 973 os.remove(tmpname)
956 raise 974 raise
Copyright (C) 2012-2017 Edgewall Software