def edict_to_csv(line):
    """
    Convert an EDICT dictionary entry into CSV.

    Given a line from an EDICT-format dictionary, attempt to convert it
    into CSV format using the "|" character. If no alternate form or
    pronunciation is available in square brackets, then it will default to
    an empty string in the corresponding CSV column. The basic format
    returned is 'term1|term2|alternate|gloss', where term1 and term2 are
    the terms, alternate is the transliteration (e.g. Pinyin or kana), and
    gloss is the set of meanings or definitions for the entry.

    """
    alt = ''
    if ' [' in line and '] ' in line and line.index(' [') < line.index('] '):
        alt = line[line.index(' [') + 2:line.index('] ')]
    if alt:
        term = line[:line.index(' [')]
    else:
        term = line[:line.index(' /')]
    gloss = line[line.index('/') + 1:line.rindex('/')].replace('/', '; ')
    if gloss[-1] != '.':
        gloss += '.'
    entry = []
    term = term.replace('|', '/')
    alt = alt.replace('|', '/')
    gloss = gloss.replace('|', '/')
    return '%s||%s|%s\n' % (term, alt, gloss)
