putenv(...) can cause hidden problems when upgrading or moving between systems which are difficult to diagnose.
On one Linux server we had the following working perfectly with setlocale
putenv("LANG=$locale");
We switched servers and found gettext wouldn't work despite having all the same locale files and settings
The recommendation to switch to
putenv("LC_ALL=$locale");
didn't fix the problem.
However,
putenv("LANGUAGE=$locale");
did. So if you have problems, check all three settings.