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.

  • Please refer to this answer be able to access Joomla classes in your own external file: stackoverflow.com/a/23937818/1362108 – Lodder Oct 30 '18 at 15:28
  • @Lodder Update question. There is no effect =( – user3774771 Oct 30 '18 at 16:50
  • I will write a proper answer this evening when Im at my computer – Lodder Oct 30 '18 at 16:51
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);
  • Thanks, adaptize your answer for my task, it's working. – user3774771 Oct 30 '18 at 18:35

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.