Search code examples
phpdatabasecakephptranslatebehavior

CakePHP - how to apply translate behavior to existing database?


I have and existing application in CakePHP with a database. The task is to apply translate behavior to its models. The problem is that i18n.php script just creates _i18n table but doesn't copy existing data to this table. Don't you know any script that could do that? Thanks for any help.


Solution

  • As far as I know, there's no way to do this. Moreover, because of the way the i18n table is configured to work, I think there's a better solution. A while back, I wrote a patch for the TranslateBehavior that will keep you from having to copy existing data into the i18n table (that felt insanely redundant to me and was a huge barrier to implementing i18n). If no record for that model exists in the i18n table, it will simply read the model record itself as a fallback.

    Unfortunately, the Cake team appears to have moved everything to new systems, so I can no longer find either the ticket or the patch that I submitted. My patched copy of the TranslateBehavior is in my Codaset repository at http://codaset.com/robwilkerson/scratchpad/source/master/blob/cakephp/behaviors/translatable.php.

    As you might expect, all of the usual warnings apply. The patched file was developed for 1.2.x and works for my needs, by YMMV.