It's an old solution. I had it in my components for 2-3 years before putting that in FOF, too. But, yep, that's pretty much how I do it:
if ($this->isBackend())
{
$paths = array(JPATH_ROOT, JPATH_ADMINISTRATOR);
}
else
{
$paths = array(JPATH_ADMINISTRATOR, JPATH_ROOT);
}
$jlang = JFactory::getLanguage();
$jlang->load($component, $paths[0], 'en-GB', true);
$jlang->load($component, $paths[0], null, true);
$jlang->load($component, $paths[1], 'en-GB', true);
$jlang->load($component, $paths[1], null, true);
Where $component is your component's name, e.g. $component = 'com_example';
Let me break it down for easier understanding. The first path ($paths[0]) is the other side of component; if we're in the back-end that's the front-end. The second path ($path[1]) is the path on this side of the component. So our code does the following:
- Load the en-GB (English) fall-back language from the other side
- Load the user preferred (or site default) language from the other side
- Load the en-GB (English) fall-back language from this side
- Load the user preferred (or site default) language from this side
The first two are particular to how my components work, sharing language keys between the front- and back-end. Most developers may want to skip them. The last two lines are those that implement the fall-back. Please remember that the fourth argument in the load() call must be true which means "overwrite existing translations with the ones we just loaded". Otherwise you'll end up with untranslated strings.
I hope that helps!
Nicholas K. Dionysopoulos