componentstranslatejoomla3.1

joomla custom component translation compatibility


What would be the best workaround to make a joomla3.1 custom component multi language platform compatible? What I mean I have the site running on 3 languages, my component should be able to show translated items of my component

realestates

  --realestate(items) - en-EN
  --realestate(items) - de-DE
  --realestate(items) - cn-CN

Would be a good workaround to extend my items table with a column translation which keeps the translation language code an each time the query would take this in consideration

select * item from realestets where translation = 'en-EN'

or there is a better way to do this?


Solution

  • For your component to be multilingual you need to define languages files which are stored in the language folder in both the administrator and public side of the website. These language files are .ini files which should be defined for every language you want to include. So if you do english and dutch your files .ini files should be in:

    /language/en-GB/en-GB.com_yourcom.ini

    /language/nl-NL/nl-NL.com_yourcom.ini

    Then every string should be passed to the translator method _() (yes that's an underscore) in the JText class like so:

    JText::_("COM_YOURCOM_STRING") where COM_YOURCOM_STRING is simply a string in your component.

    I recommend using short string descriptions if the string you are translating is a large block of text.

    EDIT: For your specific case I would add a column translation_id to your table where the items are stored. Then create a new table with 3 (or 4) columns where the translations are stored:

    id, item_id, (language), translation

    In your component xml you could add an entry which generates a dropdown to define what language your item is in. If it's anything other than the default language, it should create a new entry in the translations table.

    I would also suggest to take a look how Joomla! manages languages internally and also how Joomfish works!

    Good resources:

    http://docs.joomla.org/Embedding_translatable_strings_in_the_template

    http://docs.joomla.org/Specification_of_language_files

    http://docs.joomla.org/Language_Guidelines_for_3rd_Party_Extensions