Making a component truly Multilingual (6)
We duly released our ‘multilingual’ component Rialto, and there are just a few additional points worth mentioning before we wrap up our series of blog posts upon this topic
One cool trick that we discovered from reading the Joomla documentation is the ability load arbitrary front-end and back-end language files of any component and language. For example, you may want to load the English language file and mix it with the user's current language. This means that untranslated strings will appear in English and not as untranslated keys. You can use something like this for the back-end language files:
$language = JFactory::getLanguage(); $language->load('com_yourcomponentname', JPATH_ADMINISTRATOR, 'en-GB', true); $language->load('com_yourcomponentname', JPATH_ADMINISTRATOR, null, true);
And to load the front-end language files, using the same trick:
$language = JFactory::getLanguage(); $language->load('com_yourcomponentname', JPATH_SITE, 'en-GB', true); $language->load('com_yourcomponentname', JPATH_SITE, null, true);
This is particularly useful for the situation where not all of the ‘foreign’ language translations are up to date, yet you still wish to present an ‘intelligent’ output.
One associated use of the above is the situation where we have the front end making use of helper files from the back end, and the strings used in the helper files are (obviously) making use of the back end language files. To avoid re-specifying the strings in the front end language files we can ensure that the back end files are picked up by including the above in our helper files.
We have avoided describing how a multilingual site is set up, as this is adequately covered in many other posts upon the net. We would again strongly recommend the component named ‘JAMultiLingual’ from Joomla Arts that we have successfully used to set up a Joomla site for ‘Multilingual’ and certainly simplifies the steps in getting started into Joomla Multilingual. It is not the only possibility but one which we have used and found very well constructed.