Fallback to UTF8 encoding if locale is broken.

Fixes #7695