This is a known Windows PHP problem sind 2009 and noone in the PHP teams seems to care.
I have finally after a full day found a workaround i can live with.
NONE OF THE answers here or elsewhere did help me and also not the abandoned gettext replacement script - but it helped me to find the problem.
I even changed the windows locale - did not help - And I DO NOT want to change my Windows language as i need to debug the instant language change on my website scripts and having to reboot for each translage change is no option ;-)
I have installed the other languages and locals and nothing helped.
The problem is that you can do what you want but at leat my WIN10 64pro DID never ever look into any other folder than that of my primary windows language which is
/de_DE/LC_MESSAGES
I removed anything not relevant to the function of gettext and
these five lines remained as a minimum reproducable working example.
$path= "C:/xampp/htdocs/locale";
$domain = 'messages';
bindtextdomain($domain, $path);
textdomain($domain);
print _("The string you want to translate" );
So my idea was to change anything in these 5 lines to get different languages displayed
The path can also be relative as e.g. realpath('./locale'));
I found out that after bindtextdomain was called with a working .mp file
you have to RESTART APACHE!! to return to the default values again as obviously the language strings are cached anywhere.
So the solution to change it to get different translation was not working.
So i looked into the second argument: $domain
And the tests showed that this is perfectly suited for my puropse.
After changing it to something wrong and reloading the original none translated texts were displayed.
After changing it back to the correct one the translated texts were immediately displayed.
I felt GREAT
Now i wanted to display more than two languages.
I renamed the serbian-cyrillic! .mo and .po files of the pig example code to message1.po and message1.mo and moved themm into the
/de_DE/LC_MESSAGES
I had now 4 files in there
message.mo //german translation compiled
message.po //german translation original
message1.po // serbian cyrillic original
message1.po // serbian cyrillic original
and set the second line to "message1"
$domain = 'messages1';
AND the cyrillic code was displyed!!
I have NEITHER a cyrillic language loaded into my windows no serbian local , nothing.
Only English and GERMAN.
This means that at least in Windows 10 with german installed it is not be necessary to install the language or locale in order to get gettext working! (I do not knoy if this is also true für chinese... but that is a different story)
So if you have a remote Linux server and want to test your internationalization all you have to do is
1.) make a copy of all messages.po and -mo files
rename all of them to a desired name
e.g. messages_de.po /..mo or german.po .. whatever you like
put all those files into the folder with the name of your installed windows language
e.g. /de_DE/ or /en_US/
and change the message variable to the desired value
You might say "I DO NOT WANT TO CHANGE MY CODE OM DEPLOYMENT"
Then you just set a environment variable in Apache and and only if the script is run on your localhost windows machine with the environment context "dev" then run the Windows workaround. On your remote production system you run the standard gettext initialization.
if (getenv("SERVER_CONTEXT") == "dev")
{
switch (GET('lang')) {
case "de":
$domain="messages_de";
break;
case "fr":
$domain = "messages_fr";
break;
default: //untranslated english texts
$domain = "";
}
$path= "C:/xampp/htdocs/locale";
bindtextdomain($domain, $path);
textdomain($domain);
}
elseif (getenv("SERVER_CONTEXT") == "prod"))
{ the standard gettext initialization for the remote host }
print _("The string you want to translate" );
On your windows machine you should have the following 4 files additionally in your default language directory:
messages_fr.mo
messages_fr.po
messages_de.po
messages_de.po
NOTE: For the step of automatic detection of the system you need two small config changes:
In the Apache configuration set the follwing variable in your virtualhost of the Windows machine:
SetEnv SERVER_CONTEXT "dev"
and in the Apache configuration of the virthost of your remote production system:
SetEnv SERVER_CONTEXT "prod"