-1

I try to localize data output.

 setlocale(LC_TIME, 'et_EE.utf8');
 echo strftime("%H:%M %A, %d %B");

Instead Estonian language I get it in English format. But if I do it in Job class - all ok. In my Controller I didn't call setlocale() anymore just once setlocale(LC_TIME, 'et_EE.utf8');

Jaap
  • 81,064
  • 34
  • 182
  • 193
  • I don't understand what's the problem you face, would you clarify ? – Shady Atef Feb 15 '17 at 12:29
  • I need to get result in this example in Estonian Langugage (date) but instead i got English variant.But if this code executed in Job class (laravel framework) - all ok.Problem only if I try it to do in Controller. – Vladyslav Havrylenko Feb 15 '17 at 12:34
  • Oh, Okay.. Can you tell me what's the underlying operating system ? As In linux it depends on the installed locales – Shady Atef Feb 15 '17 at 13:39
  • Yes it's Linux and I have this locale (locale -a) "et_EE.utf8" in the list.And if try to test it for example: php -r ' setlocale(LC_TIME, 'et_EE.utf8');' I reach goal.But in my controller somethig wrong.Also when I testet it on my Win platform - all go well. – Vladyslav Havrylenko Feb 15 '17 at 13:45

2 Answers2

0

Checkout links, it describe you both way configuration level setting as well as change timezone on the fly
Stackoverflow

Laracast

Community
  • 1
  • 1
Bhaumik Pandhi
  • 2,655
  • 2
  • 21
  • 38
  • Question is not about timezone. for expl.: 1 february Wednesday in Estonian should be display - 1 Veebruar Kolmapäev – Vladyslav Havrylenko Feb 15 '17 at 12:57
  • Okay, then you need to get timezone of user and convert data into user timezone everytime. Please check this code it convert data into timezone which is stored in Cookie `$new_date = \Carbon::createFromFormat($format,$date)->setTimezone(Cookie::get('timezone')); if($type=='object'){ return $new_date; }else{ return $new_date->format($format); }` – Bhaumik Pandhi Feb 15 '17 at 13:01
  • You need to convert language or you need to convert timezone of date? – Bhaumik Pandhi Feb 15 '17 at 13:05
  • I don't need timezone, I need to display localized date from strftime("%H:%M %A, %d %B"); – Vladyslav Havrylenko Feb 15 '17 at 13:07
  • Okay, then you need to use [package](https://github.com/mcamara/laravel-localization) which set language based on URL like example.com/en, example.com/fr etc. – Bhaumik Pandhi Feb 15 '17 at 13:13
0

First of all, it's so strange for me that the set_locale works in a place and not the another, because php doesn't interfere with set_locale as it directly calls C function with the same name.

On Linux, locales must be installed in your system. To check which locales are supported use the command locale -a

you must see a list like this

en_US.utf8
et_EE.utf8

To add a locale, it differs from system to another

For ubuntu check this

For Arch and maybe others, edit the /etc/locale.gen and un-comment the wanted locale. then run sudo locale-gen

Voila your code will work..

Community
  • 1
  • 1
Shady Atef
  • 2,121
  • 1
  • 22
  • 40
  • Exacly - it works perfec from some other classes in laravel.But in controller where I call it I put result in log-file - and what I see - echo setlocale(LC_TIME, 'et_EE.utf8'); Return me empty result :( – Vladyslav Havrylenko Feb 15 '17 at 13:53
  • `set_locale` is part of php not laravel at all.. so your talk makes non-sense for me.. this needs more digging. Any way try this answer and tell me if it worked out. – Shady Atef Feb 15 '17 at 13:55