2

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.

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

1 Answer 1

3

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);
1
  • Thanks, adaptize your answer for my task, it's working. Oct 30, 2018 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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