Refactor all_languages and all_language_infos

* avoid duplicate entries in result list
* move common code in one function