Small fix for invalid locale input

Forged HTTP header could cause exception, nothing serious though.
Also added more defensive checking to UI parse_locale.