I have a site that supports these 5 languages:
Users can interchange between the languages as they want. I have a page that displays weekday date month in text like:
Monday 12th January
My code to this is:
setlocale(LC_TIME, $_SESSION['lang'] . "_" . strtoupper($_SESSION['lang']));
foreach($data['Location']['Day'] as $key => $val) {
$date = strftime("%A %e, %B", strtotime($val['@attributes']['val']));
$data['Location']['Day'][$key]['date'] = $date;
}
On localhost, when I switch between the languages, the week and month switch and work fine. However on the server, it always shows up in English for me. _SESSION['lang'] works fine and gets changed, so I don't know why it's not showing French when the locale should be fr_FR.
Could it be because there is no locales installed on the server? Or is there a better way to localise these strings?
EDIT: I've also tried appending ".utf8" in the setlocale call like this:
setlocale(LC_TIME, $_SESSION['lang'] . "_" . strtoupper($_SESSION['lang']) . ".utf8");
But that didn't work either (didn't work on localhost, nor on the server)
OK I just found out about the command locale -a
which gives a list of installed locales. On my localhost, I had everything installed (and I noticed I was doing en_EN, but that still 'worked'), Anyway on the server, it was just fr_CH (not sure what C and POSIX is for) so my code for fr_FR wasn't working and I guess everything just defaulted to English somehow.
I found out that I had to manually edit the file: /etc/locale.gen
and uncomment the languages that I needed.
I then had to do sudo locale-gen
Run the command locale -a
to verify the list of locales
Then a simple sudo /etc/init.d/apache2 restart
and refresh the page - works :)