Ticket #8536: 8536-r9833.diff

File 8536-r9833.diff, 4.5 KB (added by Ramiro Morales, 15 years ago)

Updated patch

  • django/core/management/commands/makemessages.py

    diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py
    a b  
    9090        xversion = (int(match.group('major')), int(match.group('minor')))
    9191        if xversion < (0, 15):
    9292            xgettext_reencodes_utf8 = True
    93  
     93
    9494    languages = []
    9595    if locale is not None:
    9696        languages.append(locale)
     
    128128                msgs = stdout.read()
    129129                errors = stderr.read()
    130130                if errors:
     131                    os.unlink(os.path.join(dirpath, thefile))
     132                    if os.path.exists(potfile):
     133                        os.unlink(potfile)
    131134                    raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors))
    132                 old = '#: '+os.path.join(dirpath, thefile)[2:]
    133                 new = '#: '+os.path.join(dirpath, file)[2:]
    134                 msgs = msgs.replace(old, new)
    135                 if os.path.exists(potfile):
    136                     # Strip the header
    137                     msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
    138                 else:
    139                     msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
    140135                if msgs:
     136                    old = '#: '+os.path.join(dirpath, thefile)[2:]
     137                    new = '#: '+os.path.join(dirpath, file)[2:]
     138                    msgs = msgs.replace(old, new)
     139                    if os.path.exists(potfile):
     140                        # Strip the header
     141                        msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
     142                    else:
     143                        msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
    141144                    open(potfile, 'ab').write(msgs)
    142145                os.unlink(os.path.join(dirpath, thefile))
    143146            elif domain == 'django' and (file_ext == '.py' or file_ext in extensions):
     
    154157                msgs = stdout.read()
    155158                errors = stderr.read()
    156159                if errors:
     160                    if thefile != file:
     161                        os.unlink(os.path.join(dirpath, thefile))
     162                    if os.path.exists(potfile):
     163                        os.unlink(potfile)
    157164                    raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors))
    158165
    159                 if xgettext_reencodes_utf8:
    160                     msgs = msgs.decode('utf-8').encode('iso-8859-1')
    161 
    162                 if thefile != file:
    163                     old = '#: '+os.path.join(dirpath, thefile)[2:]
    164                     new = '#: '+os.path.join(dirpath, file)[2:]
    165                     msgs = msgs.replace(old, new)
    166                 if os.path.exists(potfile):
    167                     # Strip the header
    168                     msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
    169                 else:
    170                     msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
    171166                if msgs:
     167                    if xgettext_reencodes_utf8:
     168                        msgs = msgs.decode('utf-8').encode('iso-8859-1')
     169                    if thefile != file:
     170                        old = '#: '+os.path.join(dirpath, thefile)[2:]
     171                        new = '#: '+os.path.join(dirpath, file)[2:]
     172                        msgs = msgs.replace(old, new)
     173                    if os.path.exists(potfile):
     174                        # Strip the header
     175                        msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
     176                    else:
     177                        msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
    172178                    open(potfile, 'ab').write(msgs)
    173179                if thefile != file:
    174180                    os.unlink(os.path.join(dirpath, thefile))
     
    178184            msgs = stdout.read()
    179185            errors = stderr.read()
    180186            if errors:
     187                os.unlink(potfile)
    181188                raise CommandError("errors happened while running msguniq\n%s" % errors)
    182             open(potfile, 'w').write(msgs)
    183189            if os.path.exists(pofile):
     190                open(potfile, 'w').write(msgs)
    184191                (stdin, stdout, stderr) = os.popen3('msgmerge -q "%s" "%s"' % (pofile, potfile), 't')
    185192                msgs = stdout.read()
    186193                errors = stderr.read()
    187194                if errors:
     195                    os.unlink(potfile)
    188196                    raise CommandError("errors happened while running msgmerge\n%s" % errors)
    189197            open(pofile, 'wb').write(msgs)
    190198            os.unlink(potfile)
Back to Top