forsberg
forsberg

Reputation: 1923

Moodle - new (not customized) translations

I created some additional webpages (php files) in Moodle. They're accessible of course from the appropriate path (e.g. "..my_folder/page.php").

Now I'm trying to find a solution for adding new translation entries. I noticed that I can edit existing translations in e.g. "[moodledata]/lang/[language-code]/[filename].php" files, however adding new files, or even adding new string to the existing files, has no any effect. After clearing a cache they still seem to be "invisible" for Moodle. I don't know how it works, it must be quite complicated?

How can I add new (not modify old) translation strings for Moodle? Thank you.

Upvotes: 2

Views: 1004

Answers (1)

Russell England
Russell England

Reputation: 10221

Create a lang folder for your plugin.

eg: if you are creating a local plugin then use

/local/yourpluginname/lang/en/local_yourpluginname.php

if its a block then

/block/yourblockname/lang/en/block_yourblockname.php

etc.

Then in the file have

defined('MOODLE_INTERNAL') || die();

$string['pluginname'] = 'yourpluginname';
$string['yourstringid'] = 'String you want to display';

Then call using

echo get_string('yourstringid', 'local_yourpluginname');

For more information see http://docs.moodle.org/dev/String_API

EDIT :

Nothing wrong with having traditional php pages :)

You should use the local directory for any non-standard plugins - eg:

/local/mypages/mypage1.php
/local/mypages/mypage2.php
/local/mypages/lang/en/local_mypages.php

Then call directly with

echo html_writer::link(new moodle_url('/local/mypages/mypage1.php), 
     get_string('mypage1title', 'local_mypages');

Have a look at a typical structure in

/local/readme.txt

To use the get_strings, you'll need to include the config file at the top of mypage1.php etc.

require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');

Upvotes: 1

Related Questions