CakePHP 翻译数组格式不符合预期

发布于 2024-09-05 17:34:50 字数 918 浏览 8 评论 0原文

我使用 CakePHP 版本 1.3。该文档表示,如果我想对动态内容使用翻译行为,则无需更改我的视图。问题是翻译的字段在那里,但是是空的。翻译仅出现在 ['I18n'] 数组中,就像这样

Array
(
    [0] => Array
        (
            [Category] => Array
                (
                    [id] => 1
                    [locale] => de_de
                    [name] => 
                )

            [I18n] => Array
                (
                    [name] => Anlagenkomponenten
                )

        )....

我期望这样的数组

Array
(
    [0] => Array
        (
            [Category] => Array
                (
                    [id] => 1
                    [locale] => de_de
                    [name] => Anlagenkomponenten
                )

            [I18n] => Array
                (
                    [name] => Anlagenkomponenten
                )

        )....

我的期望是错误的,还是这是一个错误?

I use CakePHP version 1.3. The documentation says that if I want to use the translation behaviour for my dynamic content, no changes in my view are necessary. The problem is that the translated fields are there, but empty. The translation only appears in the ['I18n'] array like this

Array
(
    [0] => Array
        (
            [Category] => Array
                (
                    [id] => 1
                    [locale] => de_de
                    [name] => 
                )

            [I18n] => Array
                (
                    [name] => Anlagenkomponenten
                )

        )....

I expected the Array like this

Array
(
    [0] => Array
        (
            [Category] => Array
                (
                    [id] => 1
                    [locale] => de_de
                    [name] => Anlagenkomponenten
                )

            [I18n] => Array
                (
                    [name] => Anlagenkomponenten
                )

        )....

Is my expectation wrong, or is this a bug?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怂人 2024-09-12 17:34:50

在 cakephp 1.2.6 中...在 Translate Bahavior转到第 243 行并注释到第 245 行
我认为在cakephp 1.3中也是一样

//if (!empty($results[$key]['I18n__'.$field]['content'])) {
//    $value = $results[$key]['I18n__'.$field}['content'];
//}

然后添加代码:

if (!empty($results[$key]['I18n'][$field])) {
    $value = $results[$key]['I18n'][$field];
 }

In cakephp 1.2.6... In Translate Bahavior go to line 243 and comment until 245.
I think its the same in cakephp 1.3

//if (!empty($results[$key]['I18n__'.$field]['content'])) {
//    $value = $results[$key]['I18n__'.$field}['content'];
//}

Then add the code:

if (!empty($results[$key]['I18n'][$field])) {
    $value = $results[$key]['I18n'][$field];
 }
凝望流年 2024-09-12 17:34:50

您可以发布您的数据的查找调用(也许还有该调用之上和之外的一些行)吗?

通常,翻译行为的工作方式如下:

$this->Model->locale = 'de_de';
$result = $this->Model->find('all', array( ... );

区域设置通常通过全局区域设置变量设置(一种方法是将用户的区域设置存储到会话中,并在应用程序控制器中设置全局区域设置变量)。

当未设置语言环境,并且您在模型中使用 $recursive = 1 设置执行 read() 时,Cake 会获取每个现有语言环境的所有可用翻译。

您如何为模型设置翻译行为?如果您也从模型中发布 $actsAs-variable 的翻译部分,这可能会有所帮助。

另请检查您的 i18n 表中的语言环境是否已正确保存(de_de,而不是 de-de!)。

could you post your find-call for your data (and maybe some lines above and beyond that call)?

Normally, the translation-behavior works like so:

$this->Model->locale = 'de_de';
$result = $this->Model->find('all', array( ... );

The locale is usually set via a global locale-variable (one approach is to store the locale of the user into the session and set the global locale-var in your app-controller).

When no locale is set, and you do a read() with $recursive = 1 setting in your model, Cake fetches ALL available translations for every locale existing.

How did you setup the translate-behavior for your model? It may help if you post the translate-section of your $actsAs-variable from your model, too.

Please also check your i18n-table if the locale is there is saved correctly (de_de, NOT de-de!).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文