Welcome to the Cookbook

loading...

6.3.5.1 Using the bindTranslation method

There is no translation yet for this section. Please help out and translate this.. More information about translations

You can also retrieve all translations, only when you need them, using the bindTranslation method

bindTranslation($fields, $reset)

$fields is a named-key array of field and association name, where the key is the translatable field and the value is the fake association name.

$this->Post->bindTranslation(array ('name' => 'nameTranslation'));
$this->Post->find('all', array ('recursive'=>1)); // need at least recursive 1 for this to work.
  1. $this->Post->bindTranslation(array ('name' => 'nameTranslation'));
  2. $this->Post->find('all', array ('recursive'=>1)); // need at least recursive 1 for this to work.

With this setup the result of your find() should look something like this:

Array
(
     [Post] => Array
         (
             [id] => 1
             [name] => Beispiel Eintrag 
             [body] => lorem ipsum...
             [locale] => de_de
         )

     [nameTranslation] => Array
         (
             [0] => Array
                 (
                     [id] => 1
                     [locale] => en_us
                     [model] => Post
                     [foreign_key] => 1
                     [field] => name
                     [content] => Example entry
                 )

             [1] => Array
                 (
                     [id] => 2
                     [locale] => de_de
                     [model] => Post
                     [foreign_key] => 1
                     [field] => name
                     [content] => Beispiel Eintrag
                 )

         )
)
  1. Array
  2. (
  3. [Post] => Array
  4. (
  5. [id] => 1
  6. [name] => Beispiel Eintrag
  7. [body] => lorem ipsum...
  8. [locale] => de_de
  9. )
  10. [nameTranslation] => Array
  11. (
  12. [0] => Array
  13. (
  14. [id] => 1
  15. [locale] => en_us
  16. [model] => Post
  17. [foreign_key] => 1
  18. [field] => name
  19. [content] => Example entry
  20. )
  21. [1] => Array
  22. (
  23. [id] => 2
  24. [locale] => de_de
  25. [model] => Post
  26. [foreign_key] => 1
  27. [field] => name
  28. [content] => Beispiel Eintrag
  29. )
  30. )
  31. )