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?
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.
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);
$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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With