CakePHP 翻译数组格式不符合预期
我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 cakephp 1.2.6 中...在
Translate Bahavior
中转到第 243 行并注释到第 245 行。我认为在cakephp 1.3中也是一样
然后添加代码:
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
Then add the code:
您可以发布您的数据的查找调用(也许还有该调用之上和之外的一些行)吗?
通常,翻译行为的工作方式如下:
区域设置通常通过全局区域设置变量设置(一种方法是将用户的区域设置存储到会话中,并在应用程序控制器中设置全局区域设置变量)。
当未设置语言环境,并且您在模型中使用 $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:
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!).