I have a problem with this code

<?
Header( "HTTP/1.1 301 Moved Permanently" ); 
Header( "Location: http://www.example.com" ); 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?php
$language="fr_FR";
putenv("LC_ALL=$language");
setlocale(LC_ALL, $language);
bindtextdomain("messages", "./locale");
textdomain("messages");
print "<p>"._("hi! This website is written in English.")."</p>\n";
?>
</body>
</html>

No matter what string I set the variable $language with that gettext will always look for a translation in the folder locale\es_ES\LC_MESSAGES whether the language is Spanish (es_ES) or not. For example, in the above code, gettext will not look for the French translation as it should in
locale\fr_FR\LC_MESSAGES but it will look for the translation into the folder corresponding to Spanish language, that is to say, locale\es_ES\LC_MESSAGES.

Moreover, if gettext does not find the folder locale\es_ES\LC_MESSAGES then
it will display the string in the original language(English) even if $language equals "fr_FR" and at the same time there is a locale\fr_FR\LC_MESSAGES folder created and the corresponding messages.mo and messages.po files created in this folder.

I made sure that I re-run Apache and MySql under Xampp whenever I change anything in the code but it keeps having this undesired behaviour anyways.

Do you have any idea about why only translations in .po files in the Spanish folder locale\es_ES\LC_MESSAGES are considered and not those translations corresponding to other languages and their corresponding folders?

Thanks in advance.

xxamp is terrible. Missing a whole load of functions. Get rid of it is my advice

Eventually I discovered the problem had to do with gettext being used under windows, it seems it is a bug of gettext under windows which has not been solved yet.

Member Avatar for diafol

xxamp is terrible. Missing a whole load of functions. Get rid of it is my advice

Really? Like what?

Eventually I discovered the problem had to do with gettext being used under windows, it seems it is a bug of gettext under windows which has not been solved yet.

Gettext seems to work for me when using po/mo.

Member Avatar for diafol

I see, so 5.3 is the problem. A quick check and my laptop is still on 5.2! They're taking a while to fix it. I believe that 5.2 is still available to download. No use unless you've got full control of your webserver though. Doubt whether your host would rollback!

This is not a XAMPP issue and I therefore wouldn't "get rid of it".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.