Ticket #10004: makemessages.py.diff
File makemessages.py.diff, 4.1 KB (added by , 15 years ago) |
---|
-
makemessages.py
old new 42 42 p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, close_fds=os.name != 'nt', universal_newlines=True) 43 43 return p.communicate() 44 44 45 def make_messages(locale=None, domain='django', verbosity='1', all=False, extensions=None ):45 def make_messages(locale=None, domain='django', verbosity='1', all=False, extensions=None, addcomments=False): 46 46 """ 47 47 Uses the locale directory from the Django SVN tree or an application/ 48 48 project to process all … … 106 106 for (dirpath, dirnames, filenames) in os.walk("."): 107 107 all_files.extend([(dirpath, f) for f in filenames]) 108 108 all_files.sort() 109 addcomments_switch = '' 110 if addcomments == '': 111 addcomments_switch = '--add-comments' 112 elif addcomments and len(addcomments) > 0: 113 addcomments_switch = '--addcomments=%s' % addcomments 109 114 for dirpath, file in all_files: 110 115 file_base, file_ext = os.path.splitext(file) 111 116 if domain == 'djangojs' and file_ext == '.js': … … 115 120 src = pythonize_re.sub('\n#', src) 116 121 thefile = '%s.py' % file 117 122 open(os.path.join(dirpath, thefile), "w").write(src) 118 cmd = 'xgettext -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (domain, os.path.join(dirpath, thefile))123 cmd = 'xgettext -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 %s -o - "%s"' % (domain, addcomments_switch, os.path.join(dirpath, thefile)) 119 124 msgs, errors = _popen(cmd) 120 125 if errors: 121 126 raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors)) … … 142 147 raise SyntaxError(msg) 143 148 if verbosity > 1: 144 149 sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) 145 cmd = 'xgettext -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --keyword=ugettext_noop --keyword=ugettext_lazy --keyword=ungettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (146 domain, os.path.join(dirpath, thefile))150 cmd = 'xgettext -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --keyword=ugettext_noop --keyword=ugettext_lazy --keyword=ungettext_lazy:1,2 --from-code UTF-8 %s -o - "%s"' % ( 151 domain, addcomments_switch, os.path.join(dirpath, thefile)) 147 152 msgs, errors = _popen(cmd) 148 153 if errors: 149 154 raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors)) … … 186 191 make_option('--extension', '-e', dest='extensions', 187 192 help='The file extension(s) to examine (default: ".html", separate multiple extensions with commas, or use -e multiple times)', 188 193 action='append'), 194 make_option('--add-comments', '-c', dest='addcomments', 195 help='place comment block with TAG (or those preceding keyword lines) in output file', 196 default=False), 189 197 ) 190 198 help = "Runs over the entire source tree of the current directory and pulls out all strings marked for translation. It creates (or updates) a message file in the conf/locale (in the django tree) or locale (for project and application) directory." 191 199 … … 201 209 verbosity = int(options.get('verbosity')) 202 210 process_all = options.get('all') 203 211 extensions = options.get('extensions') or ['html'] 212 addcomments = options.get('addcomments') 204 213 205 214 if domain == 'djangojs': 206 215 extensions = [] … … 210 219 if '.js' in extensions: 211 220 raise CommandError("JavaScript files should be examined by using the special 'djangojs' domain only.") 212 221 213 make_messages(locale, domain, verbosity, process_all, extensions )222 make_messages(locale, domain, verbosity, process_all, extensions, addcomments)