Fix bug when calling language_name() for a language and territory with a different query language

The query language was ignored in the fallback case for language and
territory when no exact entry for language *and* territory was found
and the territory was appended to the result for the language.

Add test cases for this  problem.