Fixed #21458 -- Made check_for_language more resistant to malformed input

Thanks to Sergey Sorokin for the report.