Fix locale parsing issues.

Fixes #1463