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 -
Wužiwarjo-wobraz wo Core developers Wužiwarjo-wobraz wo Documentation writers Wužiwarjo-wobraz wo Moodle HQ Wužiwarjo-wobraz wo Particularly helpful Moodlers Wužiwarjo-wobraz wo Peer reviewers Wužiwarjo-wobraz wo Plugin developers Wužiwarjo-wobraz wo Plugins guardians Wužiwarjo-wobraz wo Testers Wužiwarjo-wobraz wo 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)