2

I have a problem with gettext where if a user visit my website in spanish and the translation is not available for this language, the identifier is displayed instead of the english translation ?

Is there a way to avoid this ?

Here is some revelant part of my code:

$lc = 'es_ES.utf8';
putenv('LC_ALL='.$lc);
setlocale(LC_ALL, $lc);


$languageFileName = 'default';
bindtextdomain($languageFileName, ROOT_PATH.'/locale');
bind_textdomain_codeset($languageFileName, 'UTF-8');
textdomain($languageFileName);

And here is my arborescence:

-en_US
--LC_MESSAGES
---default.mo
---default.po
-es_ES
--LC_MESSAGES
---default.mo
---default.po
-fr_FR
--LC_MESSAGES
---default.mo
---default.po

Note that I'm using PHP 5.4 and my system is in french.

Nicolas BADIA
  • 5,612
  • 7
  • 43
  • 46

1 Answers1

1

I would probably check whether the desired translation is available, and if not, set a certain default locale (en_US probably) instead.

An alternative approach would be to use the default language message (ie. english) as the identifier itself. Whenever the system displays the "identifier", the user will see the english text automatically.

(Added 2013-01-31:)

To set a locale:

$locale = "en_US";

putenv("LANG=$locale");
putenv("LC_MESSAGES=$locale");
putenv("LC_NUMERIC=$locale");
putenv("LC_ALL=$locale");

$setlocale = setlocale(LC_MESSAGES, $locale);
$setlocale = setlocale(LC_TIME, $locale);
$setlocale = setlocale(LC_NUMERIC, $locale);
$setlocale = setlocale(LC_ALL, $locale);
fbitterlich
  • 882
  • 7
  • 24
  • Well, that's what I want but my question is how to do this (set a certain default locale) ! Note that my identifier is the message in french (and I don't want to change that). – Nicolas BADIA Jan 31 '13 at 08:53