Lumen fails to change locale

后端 未结 2 1726
孤城傲影
孤城傲影 2020-12-19 06:58

I have an almost fresh installation of Lumen.

I have a POST route which leads to one Controller. In the request I send lang parameter with

相关标签:
2条回答
  • 2020-12-19 07:21

    Changing locale at the runtime varying depends on the framework. You can use facade or helper function:

    For Lumen:

    Lang::setLocale('lang');
    

    or

    app('translator')->setLocale('lang');
    

    For Laravel:

    App::setLocale('lang');
    

    or

    app()->setLocale('lang');
    
    0 讨论(0)
  • 2020-12-19 07:43

    You are changing the config after it is loaded, which has no effect. To change the locale at runtime use the setLocale() method on the app instance:

    app()->setLocale($request->input('lang'));

    Edit

    The first answer seem to only work on Laravel. To change the locale at runtime with Lumen use this:

    app('translator')->setLocale($request->input('lang'));

    0 讨论(0)
提交回复
热议问题