There is no documentation on cakephp.org and I am unable to find one on google. Please link me some documentation or supply one!
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The translate behavior is another of CakePHP’s very useful but poorly documented features. I’ve implemented it a couple of times with reasonable success in multi-lingual websites along the following lines.
Firstly, the translate behavior will only internationalize the database content of your site. If you’ve any more static content, you’ll want to look at Cake’s
__('string')wrapper function andgettext(there’s some useful information about this here)Assuming there’s Contents that we want to translate with the following db table:
The content.php model then has:
in its definition. You then need to add the i18n table to the database thusly:
Then when you’re saving the data to the database in your controller, set the locale to the language you want (this example would be for Polish):
This will create entries in the i18n table for the title and body fields for the pol locale. Finds will find based on the current locale set in the user’s browser, returning an array like:
We use the excellent p28n component to implement a language switching solution that works pretty well with the gettext and translate behaviours.
It’s not a perfect system – as it creates HABTM relationships on the fly, it can cause some issues with other relationships you may have created manually, but if you’re careful, it can work well.