Improved language detection algorithm

I modified the algorithm so it first checks the extension. If there is only one language possibility, that language is used.