【问题标题】:Silverstripe fluent set localeSilverstripe 流利设置语言环境
【发布时间】:2018-07-15 13:13:14
【问题描述】:

下午好,

有人知道是否有设置语言环境手册的方法吗?我想通过 cronjob 更新数据库中一些基于语言环境的项目,但要使其工作,我必须根据一些变量而不是服务器的语言环境来设置语言环境。

【问题讨论】:

  • 您使用的是什么 SilverStripe/Fluent 版本?
  • 银条3.3

标签: php cron silverstripe fluent


【解决方案1】:

在 SilverStripe 3 版本的 Fluent 中,您可以使用 Fluent::with_locale 在给定语言环境的上下文中执行回调,例如:

Fluent::with_locale('de_DE', function () {
    $myObject = MyObject::create();
    $myObject->Title = 'German title';
    $myObject->write();
});

作为参考,在 SilverStripe 4 版本中,您可以这样做:

FluentState::singleton()->withState(function (FluentState $newState) {
    $newState->setLocale('de_DE');
    // ...
});

【讨论】:

    猜你喜欢
    • 2019-02-21
    • 2010-09-09
    • 2011-09-20
    • 1970-01-01
    • 2016-09-07
    • 2012-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多