'Check CSV file before upload'

@staticmethod
def translate_language_onvalidation(form):

    import csv
    T = current.T
    try:
        csvfile = form.vars.file.file
    except:
        form.errors['file'] = T('No    file    uploaded.')
        return
    try:
        dialect = csv.Sniffer().sniff(csvfile.read(1024))
    except csv.Error:
        error = T('Error    reading    file    (invalid    format?):    %(msg)s')
        import sys
        form.errors['file'] = (error % {'msg': sys.exc_info()[1]})
    csvfile.seek(0)
    return
