0

I want to translate dates into french. For exemple I have Thursday 15 September 2016 and I want to have Jeudi 15 Septembre 2016

My date is in dateTime format : 2016-07-20 10:51:00

I tried to do this :

setlocale (LC_TIME, 'fr_FR','fra');

echo strftime('%A %d %B %Y);

But it doesn't work for me. I have the date in english.

wxcvbn
  • 483
  • 2
  • 7
  • 20
  • setlocale (LC_TIME, 'fr_FR'); Try getting rid of the third parameter – Antony D'Andrea Sep 15 '16 at 09:56
  • Try checking the return value from `setlocale()` – Mark Baker Sep 15 '16 at 09:57
  • @AntonyD'Andrea, It doesn't change anything... – wxcvbn Sep 15 '16 at 09:58
  • Possible duplicate of [php setlocale has no effect](http://stackoverflow.com/questions/10909911/php-setlocale-has-no-effect) – Antony D'Andrea Sep 15 '16 at 09:58
  • When I do `echo setlocale (LC_TIME, 'fr_FR');` I don't have return – wxcvbn Sep 15 '16 at 09:59
  • Basically all the solutions are useless if you do not have the french locale installed on your server. – Antony D'Andrea Sep 15 '16 at 10:00
  • I tried to do this : `apt-get install locales`but it tell me that I have already intalled this – wxcvbn Sep 15 '16 at 10:02
  • Well there are multiple solutions on the question I linked that are better than the duplicate non-working answers you are getting here - just work through them. – Antony D'Andrea Sep 15 '16 at 10:03
  • @AntonyD'Andrea, I tried all solution you give me but it doesn't working – wxcvbn Sep 15 '16 at 10:08
  • @wxcvbn - you will have a return, but it;'s likely to be a __boolean__ `false`, which doesn't display anything when echoed; var_dump it rather than simply trying to echo it.... learn to debug – Mark Baker Sep 15 '16 at 10:10
  • @MarkBaker, In fact, now I have `bool(false)`. What does it mean? – wxcvbn Sep 15 '16 at 10:18
  • As per the [PHP Docs for setlocale()](http://php.net/manual/en/function.setlocale.php), `Returns... FALSE if the locale functionality is not implemented on your platform, the specified locale does not exist or the category name is invalid.`... have a look at the link in @Anthony's comment to see how to check/install locales – Mark Baker Sep 15 '16 at 10:26
  • @MarkBaker, I read @Anthony's link. When I do `locale -a` I remark I don't have fr_FR. So do `locale-gen fr_FR`and after `update-locale`. But after whe I do `locale -a`anything change... – wxcvbn Sep 15 '16 at 10:34
  • Some how the duplicate flag was "disputed", even though this question is the same as the one I linked! – Antony D'Andrea Sep 15 '16 at 12:17
  • @AntonyD'Andrea, I look at your link. It the solution, I don't have fr_FR.utf8 into locale. I tried to add this but it doesn't work – wxcvbn Sep 15 '16 at 12:21
  • @AntonyD'Andrea, It' ok it's working now, thanks a lot! – wxcvbn Sep 15 '16 at 12:49

4 Answers4

0

Try This..!

setlocale (LC_TIME, 'fr_FR.utf8','fra'); 
echo (strftime("%A %d %B %Y")); 
0

Here you go

setlocale(LC_TIME, 'fr_CA.UTF-8');
echo strftime("%A %e %B %G");

Next time try to google your question. Translating PHP date() for Multilingual Site

Community
  • 1
  • 1
Nauris Linde
  • 15
  • 1
  • 9
0

You have to check the return value of setlocale, because it will fail if the locale string is invalid, the locale you want is not installed, or some other reason

if (setlocale(LC_ALL, "") == NULL) {
    echo("Unable to set locale");
}

You can check what locales are available with locale -a. Maybe you do have a French locale installed, but you have to set it with fr_FR.utf8.

or

try this,

setlocale(LC_TIME, 'fr_CA.UTF-8');
echo strftime("%A %e %B %G");

or

try this,

setlocale(LC_TIME, 'fr_CA.UTF-8');
echo utf8_encode(strftime('%A %B %e, %Y', strtotime('2016-09-15 11:21:53')));// your date

reference

Dave
  • 3,073
  • 7
  • 20
  • 33
0

I wanted to show the date store in DB in different format and in Greek language. I post this to save some time for people that searching same problem solution.
Use this function to replace the date string from DB with your target language. Replace the Greek days and months strings. If you need another date format you need to change date_format param following directions from https://www.w3schools.com/PHP/func_date_date.asp

function TranslateDate($stringDate) {  
$MonthGR = array('Ιανουάριου', 'Φεβρουάριου', 'Μάρτιου', 'Απρίλιου', 'Μάϊου', 'Ιούνιου', 'Ιούλιου', 'Αυγούστου', 'Σεπτεμβρίου', 'Οκτωβρίου', 'Νοεμβρίου', 'Δεκεμβρίου');
$MonthEN = array('/January/', '/February/', '/March/', '/April/', '/May/', '/June/', '/July/', '/August/', '/September/', '/October/', '/November/', '/December/');

$DayGR = array('Δευτέρα', 'Τρίτη', 'Τετάρτη', 'Πέμπτη', 'Παρασκευή', 'Σάββατο', 'Κυριακή');
$DayEN = array('/Monday/', '/Tuesday/', '/Wednesday/', '/Thursday/', '/Friday/', '/Saturday/', '/Sunday/');

$hmera = preg_replace($MonthEN, $MonthGR, date_format(date_create($stringDate), 'l d F Y G:i '));
$hmera = preg_replace($DayEN, $DayGR, $hmera);

return $hmera;}
BreeZeR
  • 7
  • 3