How can I use language constant like JText::_('MY_STRING_FROM_INI_FILE') in external file?

UPD: I include joomla system files

require_once JPATH_BASE . '/includes/defines.php';
require_once JPATH_BASE . '/includes/framework.php';
require_once JPATH_BASE . '/libraries/joomla/factory.php';

$db = JFactory::getDbo();
$app = JFactory::getApplication('site');
$appUser = JFactory::getUser();

but there is effect. Language constants render like MY_STRING_INI, not value of it.

  • Please refer to this answer be able to access Joomla classes in your own external file: stackoverflow.com/a/23937818/1362108 – Lodder Oct 30 at 15:28
  • @Lodder Update question. There is no effect =( – user3774771 Oct 30 at 16:50
  • I will write a proper answer this evening when Im at my computer – Lodder Oct 30 at 16:51
up vote 3 down vote accepted

Your language files are not loaded. Load them with Joomla\CMS\Language\Language::load(). This example loads administrator/language/en-GB/en-GB.com_content.ini file:

$app = JFactory::getApplication('site');
$app->initialise();
$app->getLanguage()->load('com_content', JPATH_ADMINISTRATOR);
  • Thanks, adaptize your answer for my task, it's working. – user3774771 Oct 30 at 18:35

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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