Closed skiv3r closed 12 years ago
This will happen if you haven't removed the translated field from your primary schema. Make sure you've removed 'title' and 'body' fields from your Contents table.
hi - thanks for the Behavior! Following on the problem above, if i do remove the translated field the 'isUnique' validation seems to fail on not finding these fields. Also, what happens if there is a missing translation (e.g. i added a language later)? It seems that entries without the new translations will not show up (i would expect the default, now removed, field to be used instead).
thanks again for your work.
hi adico,
1- You can create your own customized validation,isUnique core does not support it.
2- This behavior is in any language that supports the function is defined setLocale. So you can easily add any new language.
I've tested this behavior in CakePHP 2. But in version 2.2 and .2.3, many changes were made to the original behavior. May not work properly
Thanks for the quick response! For your comments and to help anyone else, i added the following custom validation rule which seems to work (although i am not quite sure how it figures out the locale :) - but it does).
In model file (e.g. Content.php), add this:
public $validate = array(
'title' => array(
'required' => array(
'rule' => 'notEmpty',
'message' => 'Title is required'
),
'unique' => array(
'rule' => 'ensureUnique',
'message' => 'Title is not unique'
)
)
);
public function ensureUnique($check) {
// $check will have value: array('name' => 'some-value')
$fieldName = array_keys($check);
$fieldName = $fieldName[0];
$fieldValue = $check[$fieldName];
$contentI18nInstance = ClassRegistry::init('ContentI18n');
$count = $contentI18nInstance ->find('count', array('conditions' => array(
'ContentI18n.field' => $fieldName,
'ContentI18n.content' => $fieldValue)));
return ($count == 0);
}
zoghal - hi again and thanks again for the behavior.
For example:
What i was expecting in this case is that the default title field in the original Model will be used - but instead when you are in the Spanish locale - nothing is shown.
I'm sorry, my English is not so good.
1- You can use the Custom Validation Rules. IsUnique in the core does not support
2-You are right. I did not implement this feature. I do not have enough time to change. I'd be delighted if you can add this feature.
Hello, this is a good workaround for 1 page for all translation. Follow exactly your code, the ADD function works flawlessly but the EDIT does not.
public function edit($id = null) { $this->Content->setLocale(array('eng','chi')); $this->Content->id = $id; if (!$this->Content->exists()) { throw new NotFoundException(__('Invalid content')); }
Here's the debug of $this->request->data
array( 'Content' => array( 'id' => '1', 'title' => 'Welcome bla', 'body' => 'Welcomebla.', 'meta_description' => 'test', 'meta_keywords' => 'test', 'created' => '2012-05-07 06:37:20', 'modified' => '2012-05-07 06:37:20', 'locale' => 'eng' ) )