Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

joomla

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?

like image 485
Mark Simpson Avatar asked Jul 02 '13 04:07

Mark Simpson


3 Answers

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.

like image 167
Mark Simpson Avatar answered Nov 11 '22 06:11

Mark Simpson


Perhaps a version or file location difference, but in Joomla3.8.x, Mark Simpson's answered did not work for me with a component. The below did:

$lang = JFactory::getLanguage();
$extension = 'com_example';
$base_dir = JPATH_SITE;
$language_tag = 'en-GB';
$reload = true;
$lang->load($'com_example', $base_dir, $language_tag, $reload);
like image 35
GDP Avatar answered Nov 11 '22 07:11

GDP


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

I tested it with version 3.9.14 and it works because all the languages are in the path language.

The filenames are com_name, mod_name, lib_name, or tpl_name with language tag at the first part of the filename. The language tags will be added by the load function.

So my component use two language files. com_name and com_name_special. com_name should be loaded by system but my com_name_special needs to be loaded by the extra load function.

like image 1
T.Kalweit Avatar answered Nov 11 '22 07:11

T.Kalweit