'Extract translatable literals from self.file for :param domain:
creating or updating the :param potfile: POT file.
Uses the xgettext GNU gettext utility.'

def process(self, command, potfile, domain, keep_pot=False):

    from django.utils.translation import templatize
    if (command.verbosity > 1):
        command.stdout.write(('processing    file    %s    in    %s\n' % (self.file, self.dirpath)))
    (_, file_ext) = os.path.splitext(self.file)
    if ((domain == 'djangojs') and (file_ext in command.extensions)):
        is_templatized = True
        orig_file = os.path.join(self.dirpath, self.file)
        with open(orig_file) as fp:
            src_data = fp.read()
        src_data = prepare_js_for_gettext(src_data)
        thefile = ('%s.c' % self.file)
        work_file = os.path.join(self.dirpath, thefile)
        with open(work_file, 'w') as fp:
            fp.write(src_data)
        args = ['xgettext', '-d', domain, '--language=C', '--keyword=gettext_noop', '--keyword=gettext_lazy', '--keyword=ngettext_lazy:1,2', '--keyword=pgettext:1c,2', '--keyword=npgettext:1c,2,3', '--from-code=UTF-8', '--add-comments=Translators', '--output=-']
        if command.wrap:
            args.append(command.wrap)
        if command.location:
            args.append(command.location)
        args.append(work_file)
    elif ((domain == 'django') and ((file_ext == '.py') or (file_ext in command.extensions))):
        thefile = self.file
        orig_file = os.path.join(self.dirpath, self.file)
        is_templatized = (file_ext in command.extensions)
        if is_templatized:
            with open(orig_file, 'rU') as fp:
                src_data = fp.read()
            thefile = ('%s.py' % self.file)
            content = templatize(src_data, orig_file[2:])
            with open(os.path.join(self.dirpath, thefile), 'w') as fp:
                fp.write(content)
        work_file = os.path.join(self.dirpath, thefile)
        args = ['xgettext', '-d', domain, '--language=Python', '--keyword=gettext_noop', '--keyword=gettext_lazy', '--keyword=ngettext_lazy:1,2', '--keyword=ugettext_noop', '--keyword=ugettext_lazy', '--keyword=ungettext_lazy:1,2', '--keyword=pgettext:1c,2', '--keyword=npgettext:1c,2,3', '--keyword=pgettext_lazy:1c,2', '--keyword=npgettext_lazy:1c,2,3', '--from-code=UTF-8', '--add-comments=Translators', '--output=-']
        if command.wrap:
            args.append(command.wrap)
        if command.location:
            args.append(command.location)
        args.append(work_file)
    else:
        return
    (msgs, errors, status) = popen_wrapper(args)
    if errors:
        if (status != STATUS_OK):
            if is_templatized:
                os.unlink(work_file)
            if ((not keep_pot) and os.path.exists(potfile)):
                os.unlink(potfile)
            raise CommandError(('errors    happened    while    running    xgettext    on    %s\n%s' % (self.file, errors)))
        elif (command.verbosity > 0):
            command.stdout.write(errors)
    if msgs:
        if is_templatized:
            if (os.name == 'nt'):
                old = ('#:    ' + work_file)
                new = ('#:    ' + orig_file)
            else:
                old = ('#:    ' + work_file[2:])
                new = ('#:    ' + orig_file[2:])
            msgs = msgs.replace(old, new)
        write_pot_file(potfile, msgs)
    if is_templatized:
        os.unlink(work_file)
