duanliang9288 2019-04-22 12:02 采纳率: 100%
浏览 33

CakePHP LocaleSelectorMiddleware不工作

I just can't get the below code to be invoked in CakePHP 3.7. I have changed the needed language on my browser to French, but it does not work, and I only get the English version. Yes, I do have all the proper .po files in place.

public function middleware($middlewareQueue)

{
    $middlewareQueue

        // Add middleware and set the valid locales
        ->add(new LocaleSelectorMiddleware(['fr_FR']));

    return $middlewareQueue;
}
  • 写回答

1条回答 默认 最新

  • dty63504 2019-06-19 19:31
    关注

    I'm in the same situation. All I can add is that the cookbook mentions a DispatcherFactory. However, that approach seems to be deprecated.

    I haven't yet found if and by what DispatcherFactory needs to be replaced, but it could be that without it or its replacement, adding the middleware is just not enough.

    Doc for DispatcherFactory states that as of 3.3.0, middleware should be used. But I've not yet been able to get it to work.

    UPDATE: I checked my request headers, and Chrome set Accept-Language to values like 'en' and 'fr' among others. So I include what I want in my LocaleSelectorMiddleware in the correct format, and that does the trick.

    I replaced 'en_US' with 'en' for instance, and 'fr_BE' with 'fr'.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大