strings in contrib plugins

strings in contrib plugins

per Isaac Marco Blancas -
Nombre de respostes: 8
Imatge 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?


Mitjana de qualificacions: -
En resposta a Isaac Marco Blancas

Re: strings in contrib plugins

per Tim Hunt -
Imatge Core developers Imatge Documentation writers Imatge Particularly helpful Moodlers Imatge Peer reviewers Imatge Plugin developers

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

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

En resposta a Tim Hunt

Re: strings in contrib plugins

per Isaac Marco Blancas -
Imatge 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.


En resposta a Isaac Marco Blancas

Re: strings in contrib plugins

per Juan Leyva -
Imatge Core developers Imatge Moodle HQ Imatge Plugin developers Imatge 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


En resposta a Juan Leyva

Re: strings in contrib plugins

per Isaac Marco Blancas -
Imatge 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.

En resposta a Isaac Marco Blancas

Re: strings in contrib plugins

per Juan Leyva -
Imatge Core developers Imatge Moodle HQ Imatge Plugin developers Imatge 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",
                },
            },
        },
En resposta a Juan Leyva

Re: strings in contrib plugins

per Isaac Marco Blancas -
Imatge 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


En resposta a Isaac Marco Blancas

Re: strings in contrib plugins

per Juan Leyva -
Imatge Core developers Imatge Moodle HQ Imatge Plugin developers Imatge 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

En resposta a Juan Leyva

Re: strings in contrib plugins

per Isaac Marco Blancas -
Imatge 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.