Small fix for invalid locale input

Forged HTTP header could cause exception, nothing serious though.
Also added more defensive checking to UI parse_locale
Merge pull request #1579 from ares/feature/better_locale_parsing

Small fix for invalid locale input