If you come across a situation where the translation works fine on CLI but not on Apache, it may be caused by the Perl Apache module.
Basic translate.php:
<?php
putenv("LC_ALL=de_CH.UTF-8");
putenv("LANGUAGE=");
putenv("LANG=de_CH.UTF-8");
$res = setlocale(LC_ALL, 'de_CH.UTF-8', 'de_CH', 'de');
echo bindtextdomain("homepage", "./locale");
textdomain("homepage");
$results = gettext("My English Text");
if ($results === "My English Text") {
echo "Original English was returned. Something wrong\n";
} else {
echo $results;
}
?>
On the CLI the translation works:
$ php7.3 translate.php
Mein deutscher Text.
But not via Apache web server:
$ curl localhost/translate.php
Original English was returned. Something wrong
Disable Perl module and restart Apache:
# a2dismod perl
# systemctl restart apache2
And suddenly the translation works:
$ curl localhost/translate.php
Mein deutscher Text.
The exact reason for this behaviour is (as of right now) unknown to me.