Pass plugin strings into AMD module

Pass plugin strings into AMD module

by Евгений Мамаев -
Number of replies: 3
Picture of Plugin developers

How to pass strings into AMD module?

I need to show notification to user using language strings.

I do it like this

notification.addNotification(
                                            {
                                                message:M.util.get_string('getcapabilities_fail','block_myblock'),
                                                type:"error"
                                            }       
                                            );

But don`t get the right string, only getcapabilities_fail,block_myblock

Average of ratings: -
In reply to Евгений Мамаев

Re: Pass plugin strings into AMD module

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Easiest method, in PHP code:

$PAGE->requires->strings_for_js(['getcapabilities_fail'], 'block_myblock');


Average of ratings: Useful (2)
In reply to Davo Smith

Re: Pass plugin strings into AMD module

by Andreas Grabs -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Translators

Hi Davo,

I wouldn't recommend that anymore. It seems the better way is to use the amd module "core/str" to get strings in javascript. It is more flexible.

https://docs.moodle.org/dev/Useful_core_Javascript_modules#Language_strings_.28core.2Fstr.29

Best regards
Andreas

Average of ratings: Useful (2)