Here's a pragmatic solution for its software programming. When setlocale fails, it returns false.
if (!setlocale(LC_ALL, str_replace('utf-8', 'utf8', $locale)) && !setlocale(LC_ALL, str_replace('utf8', 'utf-8', $locale))) { }
In my case, it would be possible to work on our Mac computers, and the other would work on Linux CI boxes, so this solution forces the tests to pass on both.
Btw; beware of LC_ALL. Set the locale for the weakest area you need.
source share