Dr Casper Black Dr Casper Black - 5 months ago 29
PHP Question

joomla 2.5 standalone php JText::_() not working

I have a standalone file that generates an image, i included joomla framework. This file is displayed as image on the page. $_SESSION is empty and getUser returns NULL.
The JText does not know what module.language file to load and whats the default language for the user. How do I access this info/objects?

My code:

//define constant
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );

//joomla installation
define( 'JPATH_BASE', '../..' );

//include joomla core files
require_once( JPATH_BASE . DS . 'includes' . DS . 'defines.php' );
require_once( JPATH_BASE . DS . 'includes' . DS . 'framework.php' );
require_once( JPATH_BASE . DS . 'libraries' . DS . 'joomla' . DS . 'factory.php' );

$echo = JText::_("MOD_MYMODULE_TEXT");

header("Content-type: image/png");
Graph::render($echo);

Answer

use this:

$lang =& JFactory::getLanguage();
$lang->load('mod_sample',JPATH_ROOT,'fa-IR');

or sue this , detect lang automatically:

$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();

$lang =& JFactory::getLanguage();
$lang->load('mod_sample',JPATH_ROOT);
Comments