| 14 | | if os.path.isdir(os.path.join('conf', 'locale')): |
|---|
| 15 | | localedir = os.path.abspath(os.path.join('conf', 'locale')) |
|---|
| 16 | | elif os.path.isdir('locale'): |
|---|
| 17 | | localedir = os.path.abspath('locale') |
|---|
| 18 | | else: |
|---|
| 19 | | print "This script should be run from the django svn tree or your project or app tree." |
|---|
| 20 | | print "If you did indeed run it from the svn checkout or your project or application," |
|---|
| 21 | | print "maybe you are just missing the conf/locale (in the django tree) or locale (for project" |
|---|
| 22 | | print "and application) directory?" |
|---|
| 23 | | print "make-messages.py doesn't create it automatically, you have to create it by hand if" |
|---|
| 24 | | print "you want to enable i18n for your project or application." |
|---|
| 25 | | sys.exit(1) |
|---|
| | 14 | if os.path.isdir(os.path.join('conf', 'locale')): |
|---|
| | 15 | localedir = os.path.abspath(os.path.join('conf', 'locale')) |
|---|
| | 16 | elif os.path.isdir('locale'): |
|---|
| | 17 | localedir = os.path.abspath('locale') |
|---|
| | 18 | else: |
|---|
| | 19 | print "This script should be run from the django svn tree or your project or app tree." |
|---|
| | 20 | print "If you did indeed run it from the svn checkout or your project or application," |
|---|
| | 21 | print "maybe you are just missing the conf/locale (in the django tree) or locale (for project" |
|---|
| | 22 | print "and application) directory?" |
|---|
| | 23 | print "make-messages.py doesn't create it automatically, you have to create it by hand if" |
|---|
| | 24 | print "you want to enable i18n for your project or application." |
|---|
| | 25 | sys.exit(1) |
|---|
| 44 | | if domain not in ('django', 'djangojs'): |
|---|
| 45 | | print "currently make-messages.py only supports domains 'django' and 'djangojs'" |
|---|
| 46 | | sys.exit(1) |
|---|
| 47 | | if (lang is None and not all) or domain is None: |
|---|
| 48 | | print "usage: make-messages.py -l <language>" |
|---|
| 49 | | print " or: make-messages.py -a" |
|---|
| 50 | | sys.exit(1) |
|---|
| | 44 | if domain not in ('django', 'djangojs'): |
|---|
| | 45 | print "currently make-messages.py only supports domains 'django' and 'djangojs'" |
|---|
| | 46 | sys.exit(1) |
|---|
| | 47 | if (lang is None and not all) or domain is None: |
|---|
| | 48 | print "usage: make-messages.py -l <language>" |
|---|
| | 49 | print " or: make-messages.py -a" |
|---|
| | 50 | sys.exit(1) |
|---|
| 61 | | print "processing language", lang |
|---|
| 62 | | basedir = os.path.join(localedir, lang, 'LC_MESSAGES') |
|---|
| 63 | | if not os.path.isdir(basedir): |
|---|
| 64 | | os.makedirs(basedir) |
|---|
| | 61 | print "processing language", lang |
|---|
| | 62 | basedir = os.path.join(localedir, lang, 'LC_MESSAGES') |
|---|
| | 63 | if not os.path.isdir(basedir): |
|---|
| | 64 | os.makedirs(basedir) |
|---|
| 72 | | for (dirpath, dirnames, filenames) in os.walk("."): |
|---|
| 73 | | for file in filenames: |
|---|
| 74 | | if domain == 'djangojs' and file.endswith('.js'): |
|---|
| 75 | | if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) |
|---|
| 76 | | src = open(os.path.join(dirpath, file), "rb").read() |
|---|
| 77 | | src = pythonize_re.sub('\n#', src) |
|---|
| 78 | | open(os.path.join(dirpath, '%s.py' % file), "wb").write(src) |
|---|
| 79 | | thefile = '%s.py' % file |
|---|
| 80 | | cmd = 'xgettext %s -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy -o - "%s"' % ( |
|---|
| 81 | | os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile)) |
|---|
| 82 | | (stdin, stdout, stderr) = os.popen3(cmd, 'b') |
|---|
| 83 | | msgs = stdout.read() |
|---|
| 84 | | errors = stderr.read() |
|---|
| 85 | | if errors: |
|---|
| 86 | | print "errors happened while running xgettext on %s" % file |
|---|
| 87 | | print errors |
|---|
| 88 | | sys.exit(8) |
|---|
| 89 | | old = '#: '+os.path.join(dirpath, thefile)[2:] |
|---|
| 90 | | new = '#: '+os.path.join(dirpath, file)[2:] |
|---|
| 91 | | msgs = msgs.replace(old, new) |
|---|
| 92 | | if msgs: |
|---|
| 93 | | open(potfile, 'ab').write(msgs) |
|---|
| 94 | | os.unlink(os.path.join(dirpath, thefile)) |
|---|
| 95 | | elif domain == 'django' and (file.endswith('.py') or file.endswith('.html')): |
|---|
| 96 | | thefile = file |
|---|
| 97 | | if file.endswith('.html'): |
|---|
| | 72 | for (dirpath, dirnames, filenames) in os.walk("."): |
|---|
| | 73 | for file in filenames: |
|---|
| | 74 | if domain == 'djangojs' and file.endswith('.js'): |
|---|
| | 75 | if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) |
|---|
| 101 | | if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) |
|---|
| 102 | | cmd = 'xgettext %s -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy -o - "%s"' % ( |
|---|
| 103 | | os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile)) |
|---|
| 104 | | (stdin, stdout, stderr) = os.popen3(cmd, 'b') |
|---|
| 105 | | msgs = stdout.read() |
|---|
| 106 | | errors = stderr.read() |
|---|
| 107 | | if errors: |
|---|
| 108 | | print "errors happened while running xgettext on %s" % file |
|---|
| 109 | | print errors |
|---|
| 110 | | sys.exit(8) |
|---|
| 111 | | if thefile != file: |
|---|
| | 80 | cmd = 'xgettext %s -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy -o - "%s"' % ( |
|---|
| | 81 | os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile)) |
|---|
| | 82 | (stdin, stdout, stderr) = os.popen3(cmd, 'b') |
|---|
| | 83 | msgs = stdout.read() |
|---|
| | 84 | errors = stderr.read() |
|---|
| | 85 | if errors: |
|---|
| | 86 | print "errors happened while running xgettext on %s" % file |
|---|
| | 87 | print errors |
|---|
| | 88 | sys.exit(8) |
|---|
| | 95 | elif domain == 'django' and (file.endswith('.py') or file.endswith('.html')): |
|---|
| | 96 | thefile = file |
|---|
| | 97 | if file.endswith('.html'): |
|---|
| | 98 | src = open(os.path.join(dirpath, file), "rb").read() |
|---|
| | 99 | open(os.path.join(dirpath, '%s.py' % file), "wb").write(templateize(src)) |
|---|
| | 100 | thefile = '%s.py' % file |
|---|
| | 101 | if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) |
|---|
| | 102 | cmd = 'xgettext %s -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy -o - "%s"' % ( |
|---|
| | 103 | os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile)) |
|---|
| | 104 | (stdin, stdout, stderr) = os.popen3(cmd, 'b') |
|---|
| | 105 | msgs = stdout.read() |
|---|
| | 106 | errors = stderr.read() |
|---|
| | 107 | if errors: |
|---|
| | 108 | print "errors happened while running xgettext on %s" % file |
|---|
| | 109 | print errors |
|---|
| | 110 | sys.exit(8) |
|---|
| | 111 | if thefile != file: |
|---|
| | 112 | old = '#: '+os.path.join(dirpath, thefile)[2:] |
|---|
| | 113 | new = '#: '+os.path.join(dirpath, file)[2:] |
|---|
| | 114 | msgs = msgs.replace(old, new) |
|---|
| | 115 | if msgs: |
|---|
| | 116 | open(potfile, 'ab').write(msgs) |
|---|
| | 117 | if thefile != file: |
|---|
| | 118 | os.unlink(os.path.join(dirpath, thefile)) |
|---|
| 120 | | if os.path.exists(potfile): |
|---|
| 121 | | (stdin, stdout, stderr) = os.popen3('msguniq "%s"' % potfile, 'b') |
|---|
| 122 | | msgs = stdout.read() |
|---|
| 123 | | errors = stderr.read() |
|---|
| 124 | | if errors: |
|---|
| 125 | | print "errors happened while running msguniq" |
|---|
| 126 | | print errors |
|---|
| 127 | | sys.exit(8) |
|---|
| 128 | | open(potfile, 'w').write(msgs) |
|---|
| 129 | | if os.path.exists(pofile): |
|---|
| 130 | | (stdin, stdout, stderr) = os.popen3('msgmerge -q "%s" "%s"' % (pofile, potfile), 'b') |
|---|
| | 120 | if os.path.exists(potfile): |
|---|
| | 121 | (stdin, stdout, stderr) = os.popen3('msguniq "%s"' % potfile, 'b') |
|---|
| 137 | | open(pofile, 'wb').write(msgs) |
|---|
| 138 | | os.unlink(potfile) |
|---|
| | 128 | open(potfile, 'w').write(msgs) |
|---|
| | 129 | if os.path.exists(pofile): |
|---|
| | 130 | (stdin, stdout, stderr) = os.popen3('msgmerge -q "%s" "%s"' % (pofile, potfile), 'b') |
|---|
| | 131 | msgs = stdout.read() |
|---|
| | 132 | errors = stderr.read() |
|---|
| | 133 | if errors: |
|---|
| | 134 | print "errors happened while running msgmerge" |
|---|
| | 135 | print errors |
|---|
| | 136 | sys.exit(8) |
|---|
| | 137 | open(pofile, 'wb').write(msgs) |
|---|
| | 138 | os.unlink(potfile) |
|---|