Using variables in localization strings: Difference between revisions
From MoodleDocs
m (moodle 2.0 syntax change) |
No edit summary |
||
Line 13: | Line 13: | ||
The variable can then be used in your string as follows: | The variable can then be used in your string as follows: | ||
<pre>$string['stringname'] = 'This is a string with a variable called {$a}';</pre> | <pre>$string['stringname'] = 'This is a string with a variable called {$a}';</pre> | ||
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. | |||
[[Category:Developer|Localization strings and variables]] | [[Category:Developer|Localization strings and variables]] | ||
[[Category:Language]] | [[Category:Language]] |
Revision as of 08:25, 2 February 2011
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.