Wednesday, October 22, 2014

Re: i18n problem

Hi,

Here's an example:

I have an element which generates a navigation menu.

This is the code in the element:
App::import('Model', array('Shop.ShopCategory'));
$menuObj = new ShopCategory();
$nav_top = $menuObj->nav_top('');
ShopCategory has a translated 'name'-field which is also the models displayField.

In the element I have a:
foreach ($nav_top as $menuItem) {} loop

When I call this element from any other controller I can access the value of the name-field within this foreach-loop by:
$menuItem['ShopCategory']['name'] or $menuItem['ShopCategory'][$menuObj->displayField]

But when I'm in a page from the same 'shop_categories'-controller then $menuItem['ShopCategory']['name'] or $menuItem['ShopCategory'][$menuObj->displayField] (and all other translated keys) are empty.
But then I can find the desired value in $nav_top[0]['ShopCategory'][0]['ShopCategory__i18n_name']

Can anyone tell me what goes wrong here?

Thanx in advance.



On Tuesday, October 21, 2014 9:11:39 PM UTC+2, José Lorenzo wrote:
First time I see this. What Cake version are you using?

On Monday, October 20, 2014 8:56:39 AM UTC+2, Lucky1968 wrote:
Hi,

Is there anyone who can help me with this?

Thanx.

On Wednesday, October 1, 2014 9:32:05 AM UTC+2, Lucky1968 wrote:
Hi,

I'm using i18n in my application and it seems that in certain views I can use $array['translated_field'] as in other views I need to use $array[0]['Model__i18n_translated_field'] to get the same information coming from the same find in the same model.

Can anyone tell me why this is?

This is my code:

MY MODEL (SettingsSite.php):
<code>
class SettingsSite extends AppModel {

public $actsAs = array(
'Translate' => array(
'slogan'
)
);

...

public function first_site() {
return $this->find('first', array('recursive' => -1));
}

}
</code>

MY VIEWS:
<code>
App::import('Model', array('SettingsSite'));
$settingsSiteObj = new SettingsSite();
$first_site = $settingsSiteObj->first_site();
</code>

RESULTS:
In (almost) all my view files within my main application and in all my view files in plugins I get the results like this:
array(  	'SettingsSite' => array(  		...  		'locale' => 'eng',  		'slogan' => 'Translated Slogan'  	)  )
But in (apparently form-) view files in my main application I get the results like this:
array(  	'SettingsSite' => array(  		...  		'locale' => 'eng',  		'slogan' => ''  	),  	(int) 0 => array(  		'SettingsSite__i18n_slogan' => 'Translated Slogan'
) )
As said, all the code in the view files is identical and therefor pointing to the same function in the same model. And the a.m. result code is the result of debug() within the models function, so IMHO, shouldn't be influenced by anything else in the view file.

Can someone tell me why this is?

Thanx.

Luc

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: