开发者

CakePHP Translation array format not as expected

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 appea开发者_运维技巧rs 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?


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];
 }


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!).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜