I am working on a php application. Now I am trying to translate it into different languages.
To do it, I am using gettext(). But I have a problem on the configuration. I have the library correctly installed. I have gettext(textToTranslate)
around the code and I have created with no problems .mo and .po files.
The configuration on my index.php
is (working on xampp, Ubuntu):
// Language
$lang = 'es_ES';
// Domain
$text_domain = 'project';
putenv('LC_ALL='.$lang);
setlocale(LC_ALL, $lang);
bindtextdomain($text_domain, './locale' );
bind_textdomain_codeset($text_domain, 'UTF-8');
textdomain($text_domain);
and my structure of files is:
/opt/lampp/htdocs/blanca/gettext/locale/es_ES/LC_MESSAGES/project.po
/opt/lampp/htdocs/blanca/gettext/locale/es_ES/LC_MESSAGES/project.mo
But I am still seeing the code in English, qhich is the default language. Could anybody help me on this?? Thanks in advance
EDIT
@ubuntu:~$ locale -a
C
es_AR.utf8
es_BO.utf8
es_CL.utf8
es_CO.utf8
es_CR.utf8
es_DO.utf8
es_EC.utf8
es_ES.utf8
es_GT.utf8
es_HN.utf8
es_MX.utf8
es_NI.utf8
es_PA.utf8
es_PE.utf8
es_PR.utf8
es_PY.utf8
es_SV.utf8
es_US.utf8
es_UY.utf8
es_VE.utf8
POSIX
EDIT
Running a little php script under strace
comand
<?php
// Idioma
$lang = 'es_ES.utf8';
// Dominio
$text_domain = 'blanca';
// Dependiendo de tu OS putenv/setlocale configurarán tu idioma.
putenv('LC_ALL='.$lang);
setlocale(LC_ALL, $lang);
// La ruta a los archivos de traducción
bindtextdomain($text_domain, './gettext/locale' );
// El codeset del textdomain
bind_textdomain_codeset($text_domain, 'UTF-8');
// El Textdomain
textdomain($text_domain);
// Print a test message
echo gettext("User");
// Or use the alias _() for gettext()
echo _("User");
?>
Command: strace -e trace=file -o test.txt php prog.php
getcwd("/opt/lampp/htdocs/blanca", 4096) = 25 lstat("/opt/lampp/htdocs/blanca/prog.php", {st_mode=S_IFREG|0644, st_size=521, ...}) = 0 lstat("/opt/lampp/htdocs/blanca", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0 lstat("/opt/lampp/htdocs", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/opt/lampp", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/opt", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 getcwd("/opt/lampp/htdocs/blanca", 4096) = 25 lstat("/opt/lampp/htdocs/blanca/./locale", 0x7fffb2c1a670) = -1 ENOENT (No such file or directory) open("/usr/share/locale/locale.alias", O_RDONLY) = 3 open("/usr/share/locale/es_ES.utf8/LC_MESSAGES/blanca/gettext.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale/es_ES/LC_MESSAGES/blanca/gettext.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale/es.utf8/LC_MESSAGES/blanca/gettext.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale/es/LC_MESSAGES/blanca/gettext.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale-langpack/es_ES.utf8/LC_MESSAGES/blanca/gettext.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale-langpack/es_ES/LC_MESSAGES/blanca/gettext.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale-langpack/es.utf8/LC_MESSAGES/blanca/gettext.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale-langpack/es/LC_MESSAGES/blanca/gettext.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
prog.php is located in my application directory.