Can a content plugin get text from language file when it is outputting frontend html?

250 views
Skip to first unread message

Matt Thomson

unread,
May 27, 2009, 10:45:42 PM5/27/09
to Joomla! General Development
I have set up a test content plugin, the language file installs ok, it
has
MODE=Mode
in it, and the xml file has
<param name="MODE" type="list" default="1" label="MODE"
description="Select....

In the plugin manager, the visible text correctly shows as Mode, not
MODE.

In the content plugin itself, there is just:

//match {gallery 1} in the article
preg_match_all('/\{gallery ([0-9]+)\}/U',$row->text, $matches);

foreach( $matches[1] as $pluginId )
{//for every match, make the string with JText, and put that string
where {gallery 1} used to be
$pluginHtml = JText::_( 'MODE' );
$row->text = str_replace("{igallery $pluginId}",
$pluginHtml, $row->text);
}

In the article MODE is echoed out, not Mode.

I noticed that the language ini file is only put in the admin/
languages folder by the installer, so I put it in the front-end
languages folder, but still no luck.

Is the framework set up so that front end plugin JText calls are
possible, or are there any hacks to manually get a ini file, and have
it available to Jtext?

Thanks.

Matt.

Sam Moffatt

unread,
May 27, 2009, 11:13:01 PM5/27/09
to joomla-de...@googlegroups.com
By default plugins don't load language files because they aren't
always required. JPlugin has a function called "loadLanguage" which if
you call it with no params should load the language for your plugin.

Sam Moffatt
http://pasamio.id.au

Matt Thomson

unread,
May 28, 2009, 12:19:01 AM5/28/09
to Joomla! General Development
Thanks, works great.
The function let me load my component language file:
JPlugin::loadLanguage('com_igallery');
so no duplications.

Stangly enough my module (mod_igallery) automatically does this, I
guess there is some functon that checks for en-GB.mod_igallery.ini,
and if it doesn't exist, it looks for en-GB.com_igallery.ini. If there
is, it's very smart.

On May 28, 3:13 pm, Sam Moffatt <pasa...@gmail.com> wrote:
> By default plugins don't load language files because they aren't
> always required. JPlugin has a function called "loadLanguage" which if
> you call it with no params should load the language for your plugin.
>
> Sam Moffatthttp://pasamio.id.au

Sam Moffatt

unread,
May 28, 2009, 12:54:19 AM5/28/09
to joomla-de...@googlegroups.com
I'm not entirely sure I'm familiar with the behaviour you have for
modules. Modules do load their language files automatically but I
didn't think that there was any fallback to a component but I haven't
looked through modules as much as I have with plugins.

Sam Moffatt
http://pasamio.id.au
Reply all
Reply to author
Forward
0 new messages