Note:

This site is no longer used and is in read-only mode. Instead please go to our new Moodle Developer Resource site.

Using variables in localization strings

From MoodleDocs
Revision as of 08:45, 22 June 2011 by Michael de Raadt (talk | contribs) (Created page with "Language strings are defined as follows: <pre>$string['stringname'] = 'This is a string';</pre> and are called via: <pre>get_string("stringname","wherefrom")</pre> If you wis...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Language strings are defined as follows:

$string['stringname'] = 'This is a string';

and are called via:

get_string("stringname","wherefrom")

If you wish to use a variable from the calling page in the string then you will need to use the following variation to call it:

get_string("stringname","wherefrom","passedvariable")

The variable can then be used in your string as follows:

$string['stringname'] = 'This is a string with a variable called {$a}';

Note that in Moodle 1.9, the { } are optional. From Moodle 2.0 onwards, they are required, so you should get into the habit of using them now.