1

我有一个生成图像的独立文件,我包含了 joomla 框架。此文件在页面上显示为图像。$_SESSION 为空并且 getUser 返回 NULL。JText 不知道要加载什么 module.language 文件以及用户的默认语言是什么。如何访问此信息/对象?

我的代码:

//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);
4

2 回答 2

1

用这个:

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

或起诉这个,自动检测语言:

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

$lang =& JFactory::getLanguage();
$lang->load('mod_sample',JPATH_ROOT);
于 2013-04-24T09:33:07.313 回答
0

If you have been working with a component and have been using JText:: successfully, and recently you have created a plugin and to your surprise the JText:: class is not working, then please read below.

The Plugin uses its own language files. To load a language file automatically based on system language in Joomla! 3.x you need to use the following code.

$this->loadLanguage('', JPATH_BASE);

Furthermore you shall need to have a language file with the name based on the plugin name as follows.

<Language>.plg_<Plugin Type>_<Plugin name>.ini

So lets say your plugin name is coolblue and you are writing for the English (en-GB) language, and this plugin is of type authentication. So your file name would be ..

en-GB.plg_authentication_coolblue.ini

And you can store the language strings there. And Joomla! will load your language files for you, no need to discreetly specify any language or file.

于 2016-06-17T08:21:00.047 回答