def resolve(code):
    """
    Transform the given (2- or 3-letter) language code to a human readable
    language name.  The return value is a 2-tuple containing the given
    language code and the language name.  If the language code cannot be
    resolved, name will be 'Unknown (<code>)'.
    """
    if not code:
        return None, None
    if not isinstance(code, string_types):
        raise ValueError('Invalid language code specified by parser')

    # Take up to 3 letters from the code.
    code = re.split(r'[^a-z]', code.lower())[0][:3]

    for spec in codes:
        if code in spec[:-1]:
            return code, spec[-1]

    return code, u'Unknown (%r)' % code