Improve autodetection of language.

Fixes #730.
Fix the loop to search al the available languages, not only the las element.
Merge pull request #1253 from owncloud/backport-766-to-stable45-fixes-1245

Backport 766 to stable45 fixes 1245