1

I'm currently developing my first MVC component for Joomla 3.x. All in all I'm bit struggling with language/translation issues in database.

My problem is that I need to store translated content of user generated content which comes from the backend. For example someone enters a new item in German (stored in database) and needs a translation in another language. How to accomplish that in Joomla? I don't like to generate a new item for every different language when the rest is all the same.

I thought about a table "item" and a table "item_language" with that structure (strongly simplified for viewing purposes):

item

id PRIMARY INT
price DOUBLE(4,2)

item_language

itemid PRIMARY INT
language PRIMARY CHAR(5)
name VARCHAR(50)

In item_language I would like to store the different translated versions. In the language field there would be the region code (eg. de-DE) to identify the language.

My problems:

  • How to display the different (translated) versions in backend?
  • Is this the right database model?

Any help is appreciated!

Valentin Despa
  • 40,712
  • 18
  • 80
  • 106
thedom
  • 2,498
  • 20
  • 26

2 Answers2

1

You have really found yourself a nice task for a first component in Joomla!

A rather generalist answer:

  • The database model seems right. Alternatively you could encode in JSON the language data, but this could make later query operations potentially difficult. This way you will only have one table to work with.

  • As far as I know (if you are using JModel / JTable to manipulate the data) can't do this directly, as JTable is really only designed to manipulate single tables.

What you can do:

  • For editing: figure a way to represent this graphically ( for your users to see and edit this one to many relationship) and to post this data (language texts as an array) to JModel. In the model you can maintain the desired relationships and save the data using JTable.

  • Viewing (without editing) shouldn't be an issue, it would be a simple JOIN.

If you are willing to create a basic component on github, I might even give you a hand with JModel / JTable.

Valentin Despa
  • 40,712
  • 18
  • 80
  • 106
  • Thanks for your response. I'm just wondering what's the best way representing it in a JForm. The prefered way would be a custom JFormField implementation I guess for the different languages. Can you suggest something? :-) Reading and displaying the right version in a list is not the problem. I'm just wondering about the form for creating/editing an entry with different versions. Thanks! – thedom Mar 02 '14 at 18:39
  • 1
    Try finding a general JavaScript / jQuery solution that does what you need. Make it work standalone and than figure a way to do it with JFormField – Valentin Despa Mar 03 '14 at 19:34
0

I found a way to deal with the things I needed.
Thanks Valentin Despa for guiding me in the right direction :-).

Here the whole procedure (simplified - validations and exact steps omitted):

  • Define the form fields in the models/forms/site.xml as normal.
  • In views/site/tmpl/edit.php add self coded Javascript (based on jQuery) to deal with the fields which have content in multiple languages stored as JSON in database.
    • Clone the original form element and modify the needed attributes (id, name, ...) to display a special version just for the defined languages. As content - extract the JSON for the needed language from original field content and display.
    • Hide the original field with Javascript and append the customized versions to DOM.
  • Afterwards in tables/site.php I read the dynamically generated content withJInput and build together the original field by generating JSON and saving to database.

It's working like expected.

thedom
  • 2,498
  • 20
  • 26