authentication - CakePHP 3 authError 消息翻译不起作用

标签 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 文件。当我在应用程序中切换语言时,除了此闪存消息之外,一切正常......

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

#: 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'
                ]
            ],
        ],
    ]
);

感谢您的帮助;)

最佳答案

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

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

关于authentication - CakePHP 3 authError 消息翻译不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34002546/

相关文章:

php - CakePHP Auth 组件不反射(reflect)用户数据的更改

java - 来自 Java 的经过身份验证的 REST Web 服务集成

authentication - 在 .NET Core API 上使用 OpenID access_token

c++ - OpenGL翻译glm右侧还是左侧?

php - 使用翻译行为时如何查询翻译的内容?

apache - 如何使基本身份验证排除重写的 URL

c++ - 可选的 Qt 字符串翻译

Python、Django : ValueError: unsupported format character '(' (0x28) at index 3

javascript - 如何在第二个堆叠模式对话框中包含 jquery ui 小部件?

php - cakephp3 读取组件中的 session