only english in block edit form?

only english in block edit form?

by Andre Scherl -
Number of replies: 6

Hello,

I'm creating a block which contains two languages: "de" and "en"

The language files block_blockname.php are stored at /blocks/blockname/lang/de/ and /blocks/blockname/lang/en/.

In my block_edit_form I use the get_string("somestring", "block_blockname")-function but I only get the english language strings, although the choosen language is german. The block view shows the strings correctly.

Any idea for solution?

Thanks and cheers,

Andre

Average of ratings: -
In reply to Andre Scherl

Re: only english in block edit form?

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 Andre,

in Moodle 2.0, the language strings are pre-compiled and cached for performance reasons. Whenever you change the lang strings, you should either purge caches via admin link or manually remove moodledata/cache/lang/* files. Alternatively, during the development, I highly recomment you put

$CFG->langstringcache = false;

in your config.php. This will disable the strings caching and any change should appear immediately.

Average of ratings: Useful (3)
In reply to David Mudrák

Re: only english in block edit form?

by Andre Scherl -

Hey David,

thanks a lot. Only to deactivate the langstringcache wasn't enough, I also had to deactivate the langcache. Now it works fine.

I did it in the admin menu of the moodle page in "language".

I spent a lot of time for this problem, thanks for your help!

Cheers, Andre

In reply to Andre Scherl

Re: only english in block edit form?

by Andre Scherl -

Hello again!

The problem isn't solved yet.

If I change an existing language string I see the result immediately. But if I add a new language string I only get the placeholder...

In reply to Andre Scherl

Re: only english in block edit form?

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 Andre,

that is weird. Can you please elaborate a bit? What language string did you add? Are you sure you use the correct placeholder syntax {$a} or {$a->something} ? Note the curly braces are now compulsory in Moodle 2.0.
In reply to David Mudrák

Re: only english in block edit form?

by Andre Scherl -

Okay, think I got it.

I made files containing strings like $string['somestring'] = 'some string';

One file is containing english strings, the other file holds german strings. In my block I call the method get_string('blockname', 'somestring');

If I change a string which is already shown, it changes also in my block. If I add a new string only in the german language strings file, I only get placeholder. If I add the new string also in the english language file, I see all the strings like I want to.

So I have to change all language files at one go.

Thanks for your help.
Cheers, Andre

In reply to Andre Scherl

Re: only english in block edit form?

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 Andre,

correct - all Moodle code MUST define English strings first and then the translation. If a string is not defined in the English lang pack, it does not exist.

Just to fix, the correct order of the parameters is

get_string('somestring', 'block_blockname');

Cheers