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');
        // ...
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?