3
votes

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:

  • I have an index-action with a lot of records, I want the user to have the possibility to have different translations for each item (let's say: one item is translated into English(us) and German, another is translated into English(us), Italian and French, how can I give the user the possibility to edit/delete single translations?
  • I did use the $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...
1
Complex questions like this work better with the following: 1- more formatting in the question instead of a single long paragraph. 2- Code samples to help demonstrate what your are doing so the helper doesn't have to visualize everything or try to recreate it from a description.Chuck Burgess
Ok, let's try it in a more simpler way: First of all, i have records with multiple translations, i want to get the existing language/locale names that exist for each row. For instance: I have 4 rows of data, for each row there can be translations in different languages, i want to know wich languages exist for each row.AlexFr.

1 Answers

1
votes

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