Use PHP Gettext without having to install locales

Try gettext-php. It is a drop-in replacment for gettext written in PHP. It was originally done for WordPress, I think, because WP needs to run on shared hosts which are not always configured for every locale. This seems to me to be your issue as well.

It has a bit of performance hit, but it has not been an issue for me at all.


Here is the solution:

$lang = 'de'; //debug
setlocale( LC_ALL, 'C.UTF-8' );
bindtextdomain( 'default', PATH . "/locale/$lang" );
bind_textdomain_codeset( 'default', 'UTF-8' );
textdomain( 'default' );

The only difference between that and the example I posted at the bottom of my answer is that it uses C.UTF-8 not just C.

I'll be doing more testing of this, and if it works cross-platform, and will update this answer if I find out anything else.