Wrong date output on forge server Hi,
I host my app via Forge on Digital Ocean.
Actually my only problem ist, that the date I have on my page is not show in German language. I use Carbon and do:
public function today()
{
setlocale(LC_TIME, 'German');
return Carbon::now('Europe/Berlin')->formatLocalized('%d. %B %Y');
}
What I ecpect to have is:
Januar 2015
but I'll get:
January 2015 (Month is in english)
On my local machine it is working.
Does someone has an idea what I need to do?
Thanks
Andreas
Carbon docs say it works but...
setlocale(LC_TIME, 'German');
echo $dt->formatLocalized('%A %d %B %Y'); // Donnerstag 25 Dezember 1975
setlocale(LC_TIME, '');
echo $dt->formatLocalized('%A %d %B %Y'); // Thursday 25 December 1975
PHP.net says : "The return value of setlocale() depends on the system that PHP is running. It returns exactly what the system setlocale function returns." so the server should be configured to work with all languages? or what?
Isn't it easy to use a package like the one mentioned above?
Yeah but when you set it with setlocale(LC_TIME, 'German') it will change it? Just like any other PHP setting.
But it seems Not to do the expected.
How can I find out which Languages are installed with my PHP?
@ahammen i think you can make a .php file with in it
Try this command : locale -a
ok, German in definitely missing here:
How can I install that on the server? It's Digital Ocean and I use Forge.
Regards
Andreas
You can check/install languages you want on your system with this
sudo dpkg-reconfigure locales
Thanks Bashy,
I now have de_DE.UTF-8 also in the list if I do "locale -a"
But my date format is not showing correctly. Here is my code:
/**
* Shows the actual date
*
* @return Response
*/
public function today()
{
$dt = Carbon::now();
setlocale(LC_TIME, 'German');
return $dt->formatLocalized('%d. %B %Y');
}
Output on local maschine (XAMPP): 01. Februar 2015 [correct]
Output on server (Digital Ocean): 01. February 2015 [February should be Februar => German]
What is my problem here?
Thanks
Andreas
Instead of returning the date, what about seeing what the locale is set to before and after you manually set the locale?
You mean this:
$dt = Carbon::now();
setlocale(LC_TIME, '');
echo $dt->formatLocalized('%A %d %B %Y');
setlocale(LC_TIME, 'German');
echo $dt->formatLocalized('%A %d %B %Y');
On my local maschine it output for both: Sonntag 01 Februar 2015, which is German
Server for both: Sunday 01 February 2015, which is english
:-(
Any other idea?
Try this way then
setlocale(LC_TIME, 'de_DE');
No change, any other idea?
Did you restart Apache/Nginx/PHP after installing new locales?
No, I haven't
How can I do that?
I use Forge as I am not really familiar with this server stuff. :-(
Is there also a way that Forge handles this? With recipes or something?
PHP FPM
sudo service php5-fpm restart
Nginx
sudo service nginx restart
// Or you can use this to spawn new workers without interrupting current connections
sudo nginx -s reload
Apache
sudo service apache2 restart
PHP FPM and Nginx restart has been successfully.
Apache restart shows error: unrecongnized service
I also did a complete sudo reboot of the server, but still showing wrong date format. :-(
Would it be possible to have a skype or online session together and have a look on my system?
Thanks!
Sorry I should of said that you do either Nginx OR Apache. Forge normally uses Nginx so Apache won't be found.
Here is a working example of it changing locale. I believe the missing .UTF-8 was the cause.
Commands used to install and check the DE locale
bashy, thanks so much for your help.
You saved my day!
With .UTF-8 it is working now. :-)
Regards
Andreas
riessbly, you had same problem?
Please sign in or create an account to participate in this conversation.