6.3.7 Multiple Translation Tables
There is no translation yet for this section. Please help out and translate this.. More information about translations
If you expect a lot of entries you probably wonder how to deal with a rapidly growing database table. There are two properties introduced by TranslateBehavior that allow you to specify which "Model" to bind as the model containing the translations.
These are $translateModel and $translateTable.
Lets say we want to save our translations for all posts in the table "post_i18ns" instead of the default "i18n" table. To do so you need to setup your model like this:
<?php
class Post extends AppModel {
var $name = 'Post';
var $actsAs = array(
'Translate' => array(
'name'
)
);
// Use a different model (and table)
var $translateModel = 'PostI18n';
}
?> <?phpclass Post extends AppModel {var $name = 'Post';var $actsAs = array('Translate' => array('name'));// Use a different model (and table)var $translateModel = 'PostI18n';}?>
Important to note is that you have to pluralize the table. It is now a usual model and can be treated as such and thus comes with the conventions involved. The table schema itself must be identical with the one generated by the CakePHP console script. To make sure it fits one could just initialize an empty i18n table using the console and rename the table afterwards.
6.3.7.1 Create the TranslateModel
There is no translation yet for this section. Please help out and translate this.. More information about translations
For this to work you need to create the actual model file in your models folder. The reason is that there is no property to set the displayField directly in the model using this behavior yet.
Make sure that you change the $displayField to 'field'.
<?php
class PostI18n extends AppModel {
var $displayField = 'field'; // important
}
// filename: post_i18n.php
?> <?phpclass PostI18n extends AppModel {var $displayField = 'field'; // important}// filename: post_i18n.php?>
That's all it takes. You can also add all other model stuff here like $useTable. But for better consistency we could do that in the model which actually uses this translation model. This is where the optional $translateTable comes into play.
6.3.7.2 Changing the Table
There is no translation yet for this section. Please help out and translate this.. More information about translations
If you want to change the name of the table you simply define $translateTable in your model, like so:
<?php
class Post extends AppModel {
var $name = 'Post';
var $actsAs = array(
'Translate' => array(
'name'
)
);
// Use a different model
var $translateModel = 'PostI18n';
// Use a different table for translateModel
var $translateTable = 'post_translations';
}
?> <?phpclass Post extends AppModel {var $name = 'Post';var $actsAs = array('Translate' => array('name'));// Use a different modelvar $translateModel = 'PostI18n';// Use a different table for translateModelvar $translateTable = 'post_translations';}?>
Please note that you can't use $translateTable alone. If you don't intend to use a custom $translateModel then leave this property untouched. Reason is that it would break your setup and show you a "Missing Table" message for the default I18n model which is created in runtime.


























