You are viewing the PKP Support Forum | PKP Home Wiki

Variables in Locale files

OJS development discussion, enhancement requests, third-party patches and plug-ins.

Moderators: jmacgreg, btbell, michael, bdgregg, barbarah, asmecher

Forum rules
The Public Knowledge Project Support Forum is moving to http://forum.pkp.sfu.ca

This forum will be maintained permanently as an archived historical resource, but all new questions should be added to the new forum. Questions will no longer be monitored on this old forum after March 30, 2015.

Variables in Locale files

Postby tikidream » Mon Oct 14, 2013 11:36 am

Trying to add a variable in a locale file but I haven't been able to get it to work.

My steps:
1. Set the variable in the page handler
2. Reference the variable in the locale file
3. Call the locale key in the template file

I get the key back but the variable call is returned verbatum as though it weren't a variable. I suspect I may be trying to set the variable too late in the process after the locale has already been transformed, but I'm not sure if that's it, and if it is, I'm not sure where the best place to define the variable would be.

The page I'm attempting to have the variable show up on is index.php/journal/author/submissionReview/321

Expected return value
<h1>Variable: Desired Value Here</h1>

Actual returned value
<h1>Variable: {$myVar}</h1>

Here's what I've got:

Code: Select all
function submissionReview($args) {

$templateMgr->assign("myVar", "Desired Value Here");


Code: Select all
 <message key="author.article.revisions.myvar"><![CDATA[ <h1>Variable: {$myVar}</h1>]]></message>

Code: Select all
{translate key="author.article.revisions.myvar"}

Any thoughts on what might be preventing the transformation?
Posts: 6
Joined: Mon Apr 08, 2013 11:48 am

Re: Variables in Locale files

Postby JasonNugent » Tue Oct 15, 2013 6:13 am

Hi there,

If you want to do a variable replacement inside a locale key, you need to pass the variable into the {translate} smarty call:

Code: Select all
{translate key="this.is.your.locale.key" variableName="value"}

And then you'd have:

Code: Select all
<message key="this.is.your.locale.key">Some text and a {$variableName}</message>

The rest of what you've done is fine.

Site Admin
Posts: 910
Joined: Tue Jan 10, 2006 6:20 am

Re: Variables in Locale files

Postby tikidream » Tue Oct 15, 2013 8:12 am

Aha! That was the missing piece of the puzzle. Thanks!
Posts: 6
Joined: Mon Apr 08, 2013 11:48 am

Return to OJS Development

Who is online

Users browsing this forum: No registered users and 1 guest