'Guess encoding using the language, falling back on chardet.
:return: the guessed encoding.
:rtype: str'

def guess_encoding(self):

    logger.info('Guessing    encoding    for    language    %s', self.language)
    encodings = ['utf-8']
    if (self.language.alpha3 == 'zho'):
        encodings.extend(['gb18030', 'big5'])
    elif (self.language.alpha3 == 'jpn'):
        encodings.append('shift-jis')
    elif (self.language.alpha3 == 'ara'):
        encodings.append('windows-1256')
    elif (self.language.alpha3 == 'heb'):
        encodings.append('windows-1255')
    elif (self.language.alpha3 == 'tur'):
        encodings.extend(['iso-8859-9', 'windows-1254'])
    elif (self.language.alpha3 == 'pol'):
        encodings.extend(['windows-1250'])
    elif (self.language.alpha3 == 'bul'):
        encodings.extend(['windows-1251'])
    else:
        encodings.append('latin-1')
    logger.debug('Trying    encodings    %r', encodings)
    for encoding in encodings:
        try:
            self.content.decode(encoding)
        except UnicodeDecodeError:
            pass
        else:
            logger.info('Guessed    encoding    %s', encoding)
            return encoding
    logger.warning('Could    not    guess    encoding    from    language')
    encoding = chardet.detect(self.content)['encoding']
    logger.info('Chardet    found    encoding    %s', encoding)
    return encoding
