Reset locale to 'C' if the specified one is invalid

Fixes #7448