strings in contrib plugins

strings in contrib plugins

by Isaac Marco Blancas -
Number of replies: 8
Picture of Core developers
I'm triying to learn to make contrib plugins for the moodle mobile app and I have some doubts about the strings.

I don't know how to add language strings on my module to be used in a popup message. I'm only able to use language string when I add them on the /lang/en.json

I atthach a file to ilustrate it.

            lang: {
                component: "core",
                strings: {
                 "clicmyphoto": "string in the plugin",
                },

The "clicmyphoto" defined in the lang section is not loaded and I get a [ [ clicmyphoto ] ] if I don't add it on the /lang/en.json core file.

What's wrong?


Average of ratings: -
In reply to Isaac Marco Blancas

Re: strings in contrib plugins

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

In the admin settings, there is a setting 'Cache language strings'.

If you are doing development, you need to turn that off.

In reply to Tim Hunt

Re: strings in contrib plugins

by Isaac Marco Blancas -
Picture of Core developers

I don't find this option.

I can see this one: Settings > Synchronization > Enable synchronization of language files.

But it don't solve my problem.


In reply to Isaac Marco Blancas

Re: strings in contrib plugins

by Juan Leyva -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Hi Isaac,

try to change the name of the component to "local_yourplugin" or anything, see:

http://docs.moodle.org/dev/Moodle_Mobile_Developing_a_plugin_tutorial#Develop_the_MoodleMobile_plugin

Regards


In reply to Juan Leyva

Re: strings in contrib plugins

by Isaac Marco Blancas -
Picture of Core developers

Juan, the same problem renaming the plugin to local_myphoto. I'm not sure if I'm undestanding so I have uploaded my code to https://github.com/marcoblancas/moodlemobile/tree/strings-myphoto

The plugin enables a link [ [ local_myphoto ] ] . If you click it opens a popup. I am not able to diplay the strings I have set in the plugin.

In reply to Isaac Marco Blancas

Re: strings in contrib plugins

by Juan Leyva -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Sorry, I didn't explain myself correctly, what I mean with change the "component" name is to edit this attribute value:

component: "core", to "local_myphoto", you can keep the name: "myphoto"

settings: {
            name:"local_myphoto",
            type:"general",
            menuURL:"#myphoto",
            lang:{
                component:"core",
                strings:{"clicmyphoto":"string in the plugin",
                },
            },
        },
In reply to Juan Leyva

Re: strings in contrib plugins

by Isaac Marco Blancas -
Picture of Core developers

If I replace core for local_myphoto I get this error in Google Chrome when loading de app. You can see my changes on https://github.com/marcoblancas/moodlemobile/tree/strings-myphoto

Uncaught Error: Script error for: local_myphoto/main
http://requirejs.org/docs/errors.html#scripterror

File: http://192.168.1.33/moodlemobile/externallib/require.js
Line: 8


In reply to Isaac Marco Blancas

Re: strings in contrib plugins

by Juan Leyva -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

There are a couple of errors in the code:

https://github.com/marcoblancas/moodlemobile/blob/strings-myphoto/config.json#L8

As you can see you are loading the local_myphoto plugin when the correct name of the plugin is just myphoto

You need to delete the langStrings variable in the define, because it means that it's expecting to load an external resource

define(function(langStrings){ <-- incorrect

define(function() { <-- correct

In reply to Juan Leyva

Re: strings in contrib plugins

by Isaac Marco Blancas -
Picture of Core developers

I continue with problems. Certainly my config.json was with mistakes...

Now I pushed your fix but I continue with problems. I get this error:

Uncaught SyntaxError: Unexpected token o
File: http://192.168.1.33/moodlemobile/
Line: 1


If I change this line with "core" instead "local_myphoto" the things work but with no traslated strings.

https://github.com/marcoblancas/moodlemobile/blob/strings-myphoto/plugins/myphoto/main.js#L8


I think there is some problem with the support for strings for contributed plugins or I don't know how to use it. I would like to see some contrib plugin (samples in docs are core) to see how is coded the strings support.

Thank you.