1
votes

I've searched hours for a solution for this including in the documentation.

trying to use gettext for hebrew translations,

using PHP 5.3.1 and wamp,

it prints out "hello world" and not the Hebrew equivalent

$directory = '/locale';
$domain = 'messages';
$locale ="he_IL";

putenv("LANG=".$locale); //not needed for my tests, but people say it's useful for windows

setlocale( LC_ALL, $locale);
bindtextdomain($domain, $directory);
textdomain($domain);
bind_textdomain_codeset($domain, 'UTF-8');

echo _("hello world");

I use poedit to create the mo/po files, they are located on: ./locale/he_IL/LC_MESSAGES/messages.mo

the php file is at "./"

Why don't I get the hebrew text?

3
PHP isn't going to translate words into different languages for you. All it can do is switch between character sets. It's not Google Translate or Babelfish. - Marc B
Sorry that i didn't emphasize this, I know that this will not translate my words to hebrew - I am using poedit and translating it myself. - Tzvi
Here's an update, If I create an en_US folder with .po/.mo files, the translations work great, but even if you change the value of $locale to "he_IL", it won't load the new local, and will keep on showing English. I also restarted the server every-time of course. - Tzvi

3 Answers

1
votes

Ok solved,

Had to update to PHP version 5.3.5/5.3.10

and because I'm using windows I had to use this locale "Hebrew_Israel.1255" instead of "he_IL" (that's how windows calls the hebrew locale anyway).

Of course I had to also rename the folders in the ./locale to "Hebrew_Israel.1255"

Now the system successfully chooses the locale

0
votes

as pointed out by MarcB, PHP isn't magically going to translate the words into different language for you. but there are several different solutions out there to help you out. you can make use of google translator API to convert the text between different languages for example.

 try {
       $gt = new Gtranslate;
       echo "Translating [Hello World] from English to German => ".$gt->english_to_german("hello world")."<br/>";
       echo "Translating [Ciao mondo] Italian to English => ".$gt->it_to_en("Ciao mondo")."<br/>";
 } catch (GTranslateException $ge) {
       echo $ge->getMessage();
 }

you can read more about google translator API here http://code.google.com/p/gtranslate-api-php/

0
votes

You should check that "he_IL" locale is installed in your system. I don't know how to do it in Windows, but in Linux you can run "locale -a"(http://linux.about.com/library/cmd/blcmdl1_locale.htm) to see all locales installed.