Try harder to detect invalid files
Correctly handle language code at the end of filename