| 78 | | for file in filenames: |
|---|
| 79 | | if domain == 'djangojs' and file.endswith('.js'): |
|---|
| 80 | | if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) |
|---|
| | 79 | all_files.extend([(dirpath, f) for f in filenames]) |
|---|
| | 80 | all_files.sort() |
|---|
| | 81 | for dirpath, file in all_files: |
|---|
| | 82 | if domain == 'djangojs' and file.endswith('.js'): |
|---|
| | 83 | if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) |
|---|
| | 84 | src = open(os.path.join(dirpath, file), "rb").read() |
|---|
| | 85 | src = pythonize_re.sub('\n#', src) |
|---|
| | 86 | open(os.path.join(dirpath, '%s.py' % file), "wb").write(src) |
|---|
| | 87 | thefile = '%s.py' % file |
|---|
| | 88 | cmd = 'xgettext %s -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % ( |
|---|
| | 89 | os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile)) |
|---|
| | 90 | (stdin, stdout, stderr) = os.popen3(cmd, 't') |
|---|
| | 91 | msgs = stdout.read() |
|---|
| | 92 | errors = stderr.read() |
|---|
| | 93 | if errors: |
|---|
| | 94 | print "errors happened while running xgettext on %s" % file |
|---|
| | 95 | print errors |
|---|
| | 96 | sys.exit(8) |
|---|
| | 97 | old = '#: '+os.path.join(dirpath, thefile)[2:] |
|---|
| | 98 | new = '#: '+os.path.join(dirpath, file)[2:] |
|---|
| | 99 | msgs = msgs.replace(old, new) |
|---|
| | 100 | if msgs: |
|---|
| | 101 | open(potfile, 'ab').write(msgs) |
|---|
| | 102 | os.unlink(os.path.join(dirpath, thefile)) |
|---|
| | 103 | elif domain == 'django' and (file.endswith('.py') or file.endswith('.html')): |
|---|
| | 104 | thefile = file |
|---|
| | 105 | if file.endswith('.html'): |
|---|
| 85 | | cmd = 'xgettext %s -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % ( |
|---|
| 86 | | os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile)) |
|---|
| 87 | | (stdin, stdout, stderr) = os.popen3(cmd, 't') |
|---|
| 88 | | msgs = stdout.read() |
|---|
| 89 | | errors = stderr.read() |
|---|
| 90 | | if errors: |
|---|
| 91 | | print "errors happened while running xgettext on %s" % file |
|---|
| 92 | | print errors |
|---|
| 93 | | sys.exit(8) |
|---|
| | 108 | open(os.path.join(dirpath, thefile), "wb").write(templatize(src)) |
|---|
| | 109 | if verbose: |
|---|
| | 110 | sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) |
|---|
| | 111 | 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"' % ( |
|---|
| | 112 | domain, os.path.join(dirpath, thefile)) |
|---|
| | 113 | (stdin, stdout, stderr) = os.popen3(cmd, 't') |
|---|
| | 114 | msgs = stdout.read() |
|---|
| | 115 | errors = stderr.read() |
|---|
| | 116 | if errors: |
|---|
| | 117 | print "errors happened while running xgettext on %s" % file |
|---|
| | 118 | print errors |
|---|
| | 119 | sys.exit(8) |
|---|
| | 120 | if thefile != file: |
|---|
| 100 | | elif domain == 'django' and (file.endswith('.py') or file.endswith('.html')): |
|---|
| 101 | | thefile = file |
|---|
| 102 | | if file.endswith('.html'): |
|---|
| 103 | | src = open(os.path.join(dirpath, file), "rb").read() |
|---|
| 104 | | thefile = '%s.py' % file |
|---|
| 105 | | open(os.path.join(dirpath, thefile), "wb").write(templatize(src)) |
|---|
| 106 | | if verbose: |
|---|
| 107 | | sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) |
|---|
| 108 | | 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"' % ( |
|---|
| 109 | | domain, os.path.join(dirpath, thefile)) |
|---|
| 110 | | (stdin, stdout, stderr) = os.popen3(cmd, 't') |
|---|
| 111 | | msgs = stdout.read() |
|---|
| 112 | | errors = stderr.read() |
|---|
| 113 | | if errors: |
|---|
| 114 | | print "errors happened while running xgettext on %s" % file |
|---|
| 115 | | print errors |
|---|
| 116 | | sys.exit(8) |
|---|
| 117 | | if thefile != file: |
|---|
| 118 | | old = '#: '+os.path.join(dirpath, thefile)[2:] |
|---|
| 119 | | new = '#: '+os.path.join(dirpath, file)[2:] |
|---|
| 120 | | msgs = msgs.replace(old, new) |
|---|
| 121 | | if os.path.exists(potfile): |
|---|
| 122 | | # Strip the header |
|---|
| 123 | | msgs = '\n'.join(dropwhile(len, msgs.split('\n'))) |
|---|
| 124 | | else: |
|---|
| 125 | | msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8') |
|---|
| 126 | | if msgs: |
|---|
| 127 | | open(potfile, 'ab').write(msgs) |
|---|
| 128 | | if thefile != file: |
|---|
| 129 | | os.unlink(os.path.join(dirpath, thefile)) |
|---|