2

I'm spanish, and making tests internacionalizing a text width PHP, i only get it translated to english. I got this structure of files:

locale/en_US/LC_MESSAGES/con los ficheros messages.mo y messages.po
locale/es_ES/LC_MESSAGES/con los ficheros messages.mo y messages.po
locale/fr_FR/LC_MESSAGES/con los ficheros messages.mo y messages.po

Every files have the key word "Servicios" translated to each languaje.

And in PHP i have this code:

<?php
putenv("LANG=en_US");
setlocale(LC_ALL, "en_US");
bindtextdomain("messages", "locale");
textdomain("messages");
?>

When i put the code 'en_US' show the good translation, but when i change it to 'es_ES' or 'fr_FR' that way:

<?php
putenv("LANG=es_ES");
setlocale(LC_ALL, "es_ES");
?>

or

<?php
putenv("LANG=fr_FR");
setlocale(LC_ALL, "fr_FR");
?>

still showing the translation to English

I am working on Widnows 7 and the function

echo $_SERVER['HTTP_ACCEPT_LANGUAGE'] ; 

returns to "es-ES,es;q=0.8" always,

Which problem could it be? Thank you

1 Answers1

0

It is quite likely that the languages are not installed on the server your running the script on - do you have shell access to the server? Then try

locale -a

to see which locales are installed. Also have a look here Is it feasible to rely on setlocale, and rely on locales being installed?

NOTE:

be careful with the LC_ALL setting, as it may introduce some unwanted conversions. For example, I used

setlocale (LC_ALL, "Dutch");

to get my weekdays in dutch on the page. From that moment on (as I found out many hours later) my floating point values from MYSQL where interpreted as integers because the Dutch locale wants a comma (,) instead of a point (.) before the decimals. I tried printf, number_format, floatval.... all to no avail. 1.50 was always printed as 1.00 :(

When I set my locale to :

setlocale (LC_TIME, "Dutch");

my weekdays are good now and my floating point values too.

Community
  • 1
  • 1
Matheno
  • 4,112
  • 6
  • 36
  • 53
  • Hi, sorry, i don't understand the answer, how can i execute 'locale -a'?. I have a local server apache \r\n Apache Version : 2.4.9 - Documentation PHP Version : 5.5.12 - Documentation Server Software: Apache/2.4.9 (Win64) PHP/5.5.12 Thanks! – cointreau17 Oct 01 '14 at 19:31