Reputation: 354
I must say that cakephp (using the 1.3 version because project was set up with that) has a strange concept of i18n.
I did translate the static strings with success, but the dynamic ones.. cake's ideas how to manage multilingual content seems a bit, let's say, awkward to me.
I did set up the i18n table (will split that up in several tables later when I got it working) and attached the translate behavior to the desired models.
So far so good, then, in the add-actions I added a select field containing the locales (en_us, de_de...) so that the user can decide which one to save.
Before saving the records, I did a $this->Modelname->locale = $locale;
to tell the model which locale to use.
The record gets saved successfully, but, here come the problems:
$this->Modelname->bindTranslation(...)
inside actions where I needed to get the locale names (which translations existed) so that the user can decide which one to edit, is there another, more elegant way to accomplish this? Also, when i do this: $this->Modelname->bindTranslation(...);
and then instead of using the find() method, I use the paginate(), it does not return any translations...Upvotes: 3
Views: 1431
Reputation: 2232
I have a solution for Cakephp2.0 which maybe works with Cakephp1.3, too, also i've never tested. You have to rename stuff and edit some things, but it may work. In case: i recommend you to update to Cakephp2.0 as long as you are in early state of your project. 1.3 is deprecated ever since Cakephp2.1 was finally released. I went through that update process about two or three times and it's a day of work, maybe two. In my case is restarted the project from scratch. I do not really trust that updated shell although it is doing really great work.
Long story short.
My method includes overwriting the existing TranslateBehavior, added a new TranslationBehavior, a helper and a component.
Here's the zip with the files.
http://www.func0der.de/cakephp/MultiLanguageForms.zip
As soon as I figured out how to use GIT properly, i will pull request it to them. Ticket with files is already in: http://cakephp.lighthouseapp.com/projects/42648/tickets/2463-multi-language-forms#ticket-2463-4 ;)
The usage is pretty simple. In the Controller you include the component and the helper. The models gets the Translation AND the Translate behavior. The Translatio goes first because of a callback matter. But the script will throw exception else anyway.
The component will find all languages existing in the "Locale" folder by it self and safe them in into the Configure class.
In the view you use $this->Translation->inputs('Modelname.field');. The model name is important, cause i haven't figured out a way yet, to determine that automatically, because i am not sure if the FormHelper instance in my helper is the same as in the View. And i have a leak of time. ^^
The TranslationBehavior will validate EACH! of the language fields based on the field name.
If there are any questions: Ask ^^ Through i am not here very often, i will try to have a look over this question ;)
Greetings func0der
Upvotes: 1