def truncate_text(text,max_len):
    """Truncate a text string

    Given a title and an optional extension, remove characters
    and replace with ellipsis (i.e. ...) so that it fit into
    the maxium number of characters (max_len).

    """
    len_text = len(text)
    if len_text <= max_len:
        return text
    text = text[len_text-max_len:]
    return '...' + text[3:]