def METHOD_NAME(text, languages):
    script_langs = {}
    read_len = 0
    while read_len < len(text):
        script, script_len, is_ascii = get_string_script(text[read_len:])
        if script != LATIN_SCRIPT:
            script_valid = [l for l, d in languages if l in script_languages.get(script, [])]
            script_langs[script] = set(script_valid)
            if script_len == len(text) and len(script_valid) == 1:
                return script_valid[0], script_langs
        read_len += script_len
    return UNKNOWN_LANGUAGE, script_langs