Create a folder on your server and copy and paste the following code into a php script inside the folder. For this example lets call the folder example and the script index.php
<?php
// I18N support information here
$language = "en_US";
putenv("LANG=" . $language);
setlocale(LC_ALL, $language);
// Set the text domain as "messages"
$domain = "messages";
bindtextdomain($domain, "Locale");
bind_textdomain_codeset($domain, 'UTF-8');
textdomain($domain);
echo _("HELLO_WORLD");
?>
If you open the script in your browser without gettext correctly set-up you should see "HELLO_WORLD" printed to the screen.
var/www/example/Locale/en_US/LC_MESSAGES
Poedit is a cross platform editior for gettext catalogues.
$ sudo apt-get install poedit
Open poedit and go to File -> New catalog. In the settings dialog box project info tab enter the following:
In the Paths tab enter the path to the root directory of the project, be sure to add the path in both boxes:
Save to messages.po inside the LC_MESSAGES folder:
Poedit should then give you a summary of the strings to be translated:
Click OK and then create a test translation. Click on the string in the main window, it will then appear the second block below, in the third block enter in your translation. Here just as a test I have asked it to translate HELLO_WORLD into testing translation..
Click save and then exit.
$ sudo apt-get install gettext
The supported locales can be found in '/usr/share/i18n/SUPPORTED'. Open the file to see the supported languages and character sets:
$ sudo nano /usr/share/i18n/SUPPORTED
For example there are multiple lines for en_US
en_US.UTF-8 UTF-8
en_US ISO-8859-1
en_US.ISO-8859-15 ISO-8859-15
To generate the locale for the default character set, run the following:
$ sudo locale-gen en_US
$ sudo /etc/init.d/apache2 restart
This short guide is based on the following useful tutorials and QA:
http://phpmaster.com/localizing-php-applications-1/
http://stackoverflow.com/questions/5257519/cant-get-gettext-php-on-ubuntu-working