1

I use a WAMP server on Windows and make a test project. I have these files in the website folder:

C:\wamp\www\project\locale\ar_EG\LC_MESSAGES\messages.po C:\wamp\www\project\locale\en_US\LC_MESSAGES\messages.po

Below is the PHP Code:

$language="en_US";
$encoding = "UTF-8";
putenv("LANG=".$language);
setlocale(LC_ALL,$language);
$domain="messages"; // name of PO file
bindtextdomain($domain,"Locale");
bind_textdomain_codeset($domain, $encoding);
textdomain($domain);
echo gettext("name");

Above code is working fine. When I try to replace en_US with ar_EG it also displays the translation for en_US, and when I try to remove the en_US folder and try again it displays the msgid not msgstr.

I searched and found that there is a problem with setlocale on the Windows platform, but I need a solution for it to run on Windows.

Mörre
  • 5,699
  • 6
  • 38
  • 63

2 Answers2

1

setlocale() on Windows has issues.

From setLocale() in PHP Manual:

Windows users will find useful information about locale strings at Microsoft's MSDN website. Supported language strings can be found in the » language strings documentation and supported country/region strings in the » country/region strings documentation.

You might try to use $language = 'english-us'; instead of $language = 'en_US';.

I'm not sure about the language code for ar_eg, maybe Arabic_Egypt or Arabic_Egypt.1256.

If that doesn't work, you still have the option to use a PHP library, which implements gettext, like https://github.com/oscarotero/Gettext or https://launchpad.net/php-gettext.

Jens A. Koch
  • 39,862
  • 13
  • 113
  • 141
0

I made it work on windows with following code:

$locale = 'en_US';

if(!defined('LC_MESSAGES') || !setlocale(LC_ALL, $locale)) {
    putenv("LC_ALL=$locale");
}

$domain = 'messages';
$path = "C:\wamp\www\project\locale";
$codeset = 'UTF-8';

bindtextdomain($domain, $path);
textdomain($domain);
bind_textdomain_codeset($domain, $codeset);

echo gettext("name");
bitWorking
  • 12,485
  • 1
  • 32
  • 38
  • hey @bitWorking , i have no problem with en_US , my code is working fine when i use en_US. the problem happened when i use ar_EG , do u have any idea ? –  Dec 30 '14 at 12:25
  • yes i try ar_EG but it echo the english language , what is the result when u try ar_EG ?? –  Dec 30 '14 at 13:09