douliangli6407 2017-10-05 11:41
浏览 102

碳定位Laravel

Please i try to make dates to frensh and arabic in my Laravel 5.4 application, but always still in english.

this my code :

AppServiceProvider

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
     /**
      * The Config::get('app.locate') value: fr , ar
      */

     \Carbon\Carbon::setLocale(Config::get('app.locate'));
     ....
    }
}

View

{{ $user->created_at->formatLocalized('%A %d %B %Y') }}

The result is always:

"Thursday 05 October 2017"

-----------------------------------------------------------

I try also to use the setlocale function like this :

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

It work perfect in Frensh (fr) but not in Arabic (ar)

The result of setlocale(LC_TIME, 'fr_FR');

"Jeudi 05 octobre 2017"

The result of setlocale(LC_TIME, 'ar_AR');

"Thursday 05 October 2017"

-----------------------------------------------------------

I am a Mac OS user , so i check the packages languages

locale -a

I didn't found the ar_AR package, i try the locale-gen command but it don't work for me.

Any help please.

  • 写回答

1条回答 默认 最新

  • donglu9978 2017-10-05 11:52
    关注

    If you have trouble with translations, check locales installed in your system (local and production). locale -a to list locales enabled.

    sudo locale-gen fr_FR.UTF-8 to install a new locale.

    sudo dpkg-reconfigure locales to publish all locale enabled. And reboot your system.

    Unfortunately the base class DateTime does not have any localization support. To begin localization support a formatLocalized($format) method was added. The implementation makes a call to strftime using the current instance timestamp. If you first set the current locale with PHP function setlocale() then the string returned will be formatted in the correct locale.

    setlocale(LC_TIME, 'German');
    echo $dt->formatLocalized('%A %d %B %Y');          // Mittwoch 21 Mai 1975
    setlocale(LC_TIME, '');
    echo $dt->formatLocalized('%A %d %B %Y');          // Wednesday 21 May 1975
    

    Ref: http://carbon.nesbot.com/docs/

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。