Search code examples
joomla

How does one load a language file for a 3rd party Joomla extension?


The normal way to load a language file located in the admin app is like so:

$language = JFactory::getLanguage();
$language->load('com_yourcomponentname', JPATH_ADMINISTRATOR);

And to load a language file from the site app:

$language = JFactory::getLanguage();
$language->load('com_yourcomponentname', JPATH_SITE);

These methods load language files from /administrator/language and /language respectively.

Presently, I need to load a language file from a module that locates its language files at /modules/mod_foo/language. How would I do that?


Solution

  • OK, it's as simple as replacing JPATH_SITE with the full path to the module like so:

    $language = JFactory::getLanguage();
    $language->load('mod_foo', JPATH_SITE.'/modules/mod_foo');
    

    This of course assumes that the language file you want to load is located at:

    /modules/mod_foo/language/xx-XX/xx-XX.mod_foo.ini
    

    I had tried this before posting the question, but it didn't work due to a silly typo.