PHP locale not working in Ubuntu

I was working with Laravel 4 and trying to format Carbon object dates according to locale. However App::setLocale(‘et_EE’) did not have any effect. Going lower level and setting setlocale(LC_ALL, ‘et_EE’) did not change locale either. Carbon uses under formatLocalized method PHP strftime so issue relates to this also. Some have suggested to use

utf8_encode(strftime("%A, %d de %B",time()));

But it is not perfect solution either.

It turns out that OS must support the locale. You can check all available locales in your machine with

locale -a

If your webapp supported locales are missing then add these with command

locale-gen en_US et_EE

Removing locales is easy also, just add –purge to the command, which removes all other locales and keeps only the ones you specify.

locale-gen --purge en_US et_EE

I had another specific issue with locale et_EE, by default it is encoded in ISO-8859-15 ( et_EE.iso885915 ). If all application is in UTF-8 then dates will have special chares ÜÕÖÄ corrupted. To force UTF-8 only ( et_EE => et_EE.utf8 ) I had to make changes in this file

/usr/share/i18n/SUPPORTED

and edit there line et_EE ISO-8859-15 to et_EE UTF-8

 

 


Leave a Reply

Your email address will not be published.


*