Variables in language pack strings

Variables in language pack strings

by Charlie Owen -
Number of replies: 2

Hi all,

Could someone give me some pointers on how to insert variables into language pack strings? There are a lot of examples in the Moodle language packs that go something like:

 $string['periodnminutes'] = 'last $a minutes';

(This example is taken from the Online Users block)

How and where is $a defined? I can't see anything obvious - the relevant php files don't have anything like:

 $a = <code to generate minutes>;

Am I missing something really blatant? If there's a doc page I've overlooked then please let me know! wink

Average of ratings: -
In reply to Charlie Owen

Re: Variables in language pack strings

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
You set $a when you call get_string. In this case you would want

get_string('periodnminutes', 'mylangfile', (int)($timeinseconds/60));
In reply to Tim Hunt

Re: Variables in language pack strings

by Charlie Owen -
Perfect! So easy to overlook things before the first mid-morning coffee... wink

Thanks Tim.

(I've added this to the Docs as I couldn't find anything about it in there)