Block language files

Block language files

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
Ngā whakawākanga toharite: -
In reply to Simon Hanmer

Re: Block language files

David Mudrák -
Pikitia o Core developers Pikitia o Documentation writers Pikitia o Moodle HQ Pikitia o Particularly helpful Moodlers Pikitia o Peer reviewers Pikitia o Plugin developers Pikitia o Plugins guardians Pikitia o Testers Pikitia o 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

Ngā whakawākanga toharite: Useful (1)