get_string() in String API

get_string() in String API

by Andika Yudha Utomo -
Number of replies: 3

Dear all,

I wanna creates and retrieves strings in my course format, call it xformat.

So I create some strings in course/format/xformat/lang/en/format_xformat.php like this

$string['hello'] = 'Hi';
$string['welcome'] = 'Welcome to ';

I want to retrieve that string in the renderer file, I read String API format it should be like this;

get_string('hello', 'format_xformat', null, true);

I didnt get the strings, but I get this

[#[#hello#]#] (without #)

 

Could somebody help me what should I do? Is that something wrong in my code? I have look around at google and found no idea about this matters.

 

Thanks

 

Average of ratings: -
In reply to Andika Yudha Utomo

Re: get_string() in String API

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

You may have to Purge All Caches, as language strings are cached

Average of ratings: Useful (1)
In reply to Andika Yudha Utomo

Re: get_string() in String API

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

During the development, it is usually better to switch the language string caches of, e.g. via

$CFG->langstringcache = false;

in the config.php. It should work then.

Also note, the 4th parameter for the get_string() - the $lazyload - is not usually needed. It is there for rather special cases when Moodle would need to load huge amount of strings even if they were not actually displayed (such as when the whole admin menu tree is populated). For normal usage - such as yours - it's better to pass just two or three parameters.

Average of ratings: Useful (1)