This moves management of the LC_MESSAGES environment variable into an automatic variable. Previously if an error occurred the original environment value was not restored. This makes the fix to issue #5936 more robust.