2

it is boring that lots of code must be created in a Joomla component for backend and also front end. So I would like to use the administrator language file of my custom component for my front end. I found this piece of useful code:

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

But where should I include that piece of code? I've tried it in the index.html file of my frontend template. But this doesn't work!

I've also tried at the beginning of the templates index.html:

$language = JFactory::getLanguage();
$extension = 'com_yourcomponentname';
$base_dir = JPATH_ADMINISTRATOR . DS . 'components' . DS . $extension;
$language_tag = $language->getTag(); // loads the current language-tag

$language->load($extension, $base_dir, $language_tag, true);
$paths = $language->getLanguagePath();

$paths shows me an array with all loaded components including my custom component. The last entry of the array of my custom component refers correct to my administration language file of my component.

D:\htdocs\test\language\en-GB\en-GB.com_yourcomponentname
D:\htdocs\test\language\de-DE\de-DE.com_yourcomponentname
D:\htdocs\test\components\com_yourcomponentname\language\en-EN\en-EN.com_yourcomponentname
D:\htdocs\test\components\com_yourcomponentname\language\de-DE\de-DE.com_yourcomponentname
D:\htdocs\test\administrator\components\com_yourcomponentname\language\en-EN\en-EN.com_yourcomponentname
D:\htdocs\test\administrator\components\com_yourcomponentname\language\de-DE\de-DE.com_yourcomponentname

But the translation of the variables are still not be made. The translation in the backend is working fine with that same file.

1

Setting the instructions in the yourcomponent.php site entry point will do!

Put this commands in the yourcomponent.php:

$language = JFactory::getLanguage();
$extension = 'com_yourcomponentname';
$base_dir = JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . $extension;
$language_tag = $language->getTag(); // loads the current language-tag
$language->load($extension, $base_dir, $language_tag, true);

If you want to load from administrator/languages use this code:

$language = JFactory::getLanguage();
$extension = 'com_yourcomponentname';
$language_tag = $language->getTag(); // loads the current language-tag
$base_dir = JPATH_ADMINISTRATOR;
$language->load($extension, $base_dir, $language_tag, true);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.