CakePHP 3 authError消息转换无法正常工作

时间:2015-11-30 15:51:25

标签: authentication translation cakephp-3.0

我有CakePHP 3的应用程序。 我的应用程序是法语和英语。

在我的UsersController函数initialize()中,我说:

'authError' => __('Vous devez vous identifier pour accéder à cette zone.')

在我的en_US / default.po(使用poedit生成)中,我有:

#: Controller/SavsController.php:35 Controller/UsersController.php:29
msgid "Vous devez vous identifier pour accéder à cette zone."
msgstr "Login to access this area."

但翻译不起作用......这条消息总是用法语,为什么?任何人都有这个问题吗?

我将默认语言设置为' fr_FR'在我的配置中,我为fr_FR和en_US生成了.pot和po文件。当我在我的应用程序中切换语言时,除了这个flash消息外,一切正常...

其他信息效果很好,例如:

#: Template/Pages/home.ctp:44
msgid "Accès Espace Client"
msgstr "Customer Area Access"

我的初始化函数的代码:

parent::initialize();
$this->loadComponent(
    'Auth', [
        'loginRedirect' => [
            'controller' => 'Users', 'action' => 'home'
        ], 'logoutRedirect' => [
            'controller' => 'Users', 'action' => 'logout'
        ], 'loginAction' => [
            'controller' => 'Users', 'action' => 'login'
        ], 'logoutAction' => [
            'controller' => 'Users', 'action' => 'logout'
        ],
        'authError' => __('Vous devez vous identifier pour accéder à cette zone.'), 
        'authenticate' => [
            'Cotral' => [
                'fields' => [
                    'email' => 'email', 'password' => 'password'
                ]
            ],
        ],
    ]
);

感谢您的帮助;)

1 个答案:

答案 0 :(得分:2)

您可能会在beforeFilter()中切换语言,在 initialize()后称为

您可以在加载AuthComponent之前实现语言切换逻辑,也可以更新authErrorbeforeFilter键的值。