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
Developer Resources:

Documentation: The OJS Technical Reference and the OJS API Reference are both available from the OJS Documentation page.

Git: You can access our public Git Repository here. Comprehensive Git usage instructions are available on the wiki.

Bugzilla: You can access our Bugzilla report tracker here.

Search: You can use our Google Custom Search to search across our main website, the support forum, and Bugzilla.

Questions and discussion are welcome, but if you have a workflow or usability question you should probably post to the OJS Editorial Support and Discussion subforum; if you have a technical support question, try the OJS Technical Support subforum.

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 4 guests