doudao1369 2018-02-05 16:05
浏览 124
已采纳

Silverstripe流利的设置语言环境

Good afternoon,

Does somebody know if there is a method to set locale manual? I want to update some locale based items in the database by a cronjob, but to make it work I have to set locale based on some variables instead of the locale of the server.

  • 写回答

1条回答 默认 最新

  • douchui1657 2018-02-06 10:50
    关注

    In the SilverStripe 3 version of Fluent you can use Fluent::with_locale to perform a callback under the context of a given locale, e.g.:

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

    For reference, in the SilverStripe 4 version you can do this instead:

    FluentState::singleton()->withState(function (FluentState $newState) {
        $newState->setLocale('de_DE');
        // ...
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效