diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py
a
|
b
|
|
10 | 10 | from django.core.management.base import CommandError, BaseCommand |
11 | 11 | |
12 | 12 | pythonize_re = re.compile(r'\n\s*//') |
| 13 | plural_forms_re = re.compile(r'^(?P<value>"Plural-Forms.+?\\n")\s*$', re.MULTILINE | re.DOTALL) |
13 | 14 | |
14 | 15 | def handle_extensions(extensions=('html',)): |
15 | 16 | """ |
… |
… |
|
36 | 37 | # trick xgettext to parse them as Python files) |
37 | 38 | return set([x for x in ext_list if x != '.py']) |
38 | 39 | |
| 40 | def copy_django_plural_forms(msgs, loc, domain): |
| 41 | """ |
| 42 | Copies plural forms header contents from a Django catalog of locale loc to |
| 43 | the msgs string, inserting it at the right place. msgs should be the |
| 44 | contents of a newly created .po file. |
| 45 | """ |
| 46 | django_dir = os.path.normpath(os.path.join(os.path.dirname(__file__), '../../..')) |
| 47 | if domain == 'djangojs': |
| 48 | domains = ('djangojs', 'django') |
| 49 | else: |
| 50 | domains = ('django',) |
| 51 | for domain in domains: |
| 52 | django_po = os.path.join(django_dir, 'conf/locale/%s/LC_MESSAGES/%s.po' % (loc, domain)) |
| 53 | if os.path.exists(django_po): |
| 54 | m = plural_forms_re.search(open(django_po, 'rU').read()) |
| 55 | if m: |
| 56 | #sys.stderr.write("value: %s\n" % m.group('value')) |
| 57 | lines = [] |
| 58 | seen = False |
| 59 | for line in msgs.split('\n'): |
| 60 | if not line and not seen: |
| 61 | line = '%s\n' % m.group('value') |
| 62 | seen = True |
| 63 | lines.append(line) |
| 64 | msgs = '\n'.join(lines) |
| 65 | break |
| 66 | return msgs |
| 67 | |
39 | 68 | def make_messages(locale=None, domain='django', verbosity='1', all=False, extensions=None): |
40 | 69 | """ |
41 | 70 | Uses the locale directory from the Django SVN tree or an application/ |
… |
… |
|
50 | 79 | |
51 | 80 | from django.utils.translation import templatize |
52 | 81 | |
| 82 | invoked_for_django = False |
53 | 83 | if os.path.isdir(os.path.join('conf', 'locale')): |
54 | 84 | localedir = os.path.abspath(os.path.join('conf', 'locale')) |
| 85 | invoked_for_django = True |
55 | 86 | elif os.path.isdir('locale'): |
56 | 87 | localedir = os.path.abspath('locale') |
57 | 88 | else: |
… |
… |
|
173 | 204 | errors = p.stderr.read() |
174 | 205 | if errors: |
175 | 206 | raise CommandError("errors happened while running msgmerge\n%s" % errors) |
| 207 | elif not invoked_for_django: |
| 208 | msgs = copy_django_plural_forms(msgs, locale, domain) |
176 | 209 | open(pofile, 'wb').write(msgs) |
177 | 210 | os.unlink(potfile) |
178 | 211 | |