Block language files

Block language files

by Simon Hanmer -
Number of replies: 2
Apologies if this is the wrong area...

I'm dabbling with writing my first block and one of the needs I'd like to cover is for it to have language strings but I'm having some problems finding the correct location for the language file.

The block I'm writing is using the name userclock so is placed in the directory blocks/userclock - within that directory I have block_userclock.php (block code) and also a directory lang/en_utf8 (giving path of $CFG->dirroot/blocks/userclock/lang/en_utf8) containing a file called block_userclock.php. This file contains the lines:

<?php
$string['block_title'] = "User Clock";
?>

I try to access the string using

$text = get_string("block_title", "userclock");

but this just returns [ [ block_title ] ] (without the spaces)

Obviously I'm doing something wrong or I've missed something - if someone could suggest what I need to do it'd be much appreciated.

Thanks,
Simon
Average of ratings: -
In reply to Simon Hanmer

Re: Block language files

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

Hi Simon,

you must use

$text = get_string("block_title", "block_userclock");

If you omit the block_ prefix, Moodle expects you want a string from activity module mod/userclock

Average of ratings: Useful (1)