I create a messages.po and messages.mo files using poedit that contain strings which i want to show in spanish language.
To show my translations, i am using
<?php echo _("My text"); ?>
But i am facing the problem to load these files for translating my site text.
Here is the code which i am using to load the translations:
$locale = "en_US";
if (isset($_GET["lang"])) $locale = $_GET["lang"];
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain("messages", "./languages");
textdomain("messages");
The languages folder is placed in the root and the the directory structure is
languages/es_ES/LC_MESSAGES/messages.po
I am using http://mydomain?lang=es_ES in the url to run the site in spanish language.
Please tell me where i am wrong.