Reputation: 3444
I try to use "gettext" in my app without success.
Here is my file in which I initialize somethings :
//methode gettext
switch (Input::get('langue')) {
case 'fr_FR': $boo_retour_putenv = putenv("LANG=fr_FR");
break;
case 'en_GB': $boo_retour_putenv = putenv("LANG=en_GB");
break;
case 'de_DE': $boo_retour_putenv = putenv("LANG=de_DE");
break;
}
// comment s'appelle le fichier contenant les traductions ?
$stg_retour_textdomain = textdomain("messages");
// où se trouve le fichier contenant les traductions ?
$stg_retour_bindtextdomain = bindtextdomain("messages", app_path().DIRECTORY_SEPARATOR."lang");
// préciser ici que le fichier des traductions est en codage UTF-8
$stg_retour_bind_textdomain_codeset = bind_textdomain_codeset("messages", "UTF-8");
After this script, all seems OK into the vars.
I have this directories for the translations :
Into these messages files, I can see the right translations. But when I try a :
<?php echo gettext('something') ?>
it is not translated.
I must not be far away from the solution but I would appreciate any help.
NB : It used with LARAVEL 4.2 I use poedit to build the messages.mo
Thanks
Dominique
Upvotes: 1
Views: 139
Reputation: 13107
Try setting the locale with setlocale
after the textdomain
and bindtextdomain
calls:
$locale = 'fr_FR';
setlocale(LC_ALL, "$locale.utf8");
setlocale(LC_NUMERIC, "en_US.utf8"); // for sprintf() etc.
It is very important that the selected locale is present on the system, with exactly the same name as the string which you pass to setlocale
. For the above example this means that the fr_FR.utf8
locale must exist. You can check which locales are available with
locale -a
on the command line.
Upvotes: 1