A little Problem with the language system - Better Battlelog Forums #66851

Sitemap
Topicstarter
Hi there,

i got a little problem with my Plugin Source.
It replaces the COOP button on the home-page with a link to your server favourites.

Folowing works fine:
BBLog.handle("add.plugin", {
//plugin ID
id : "coop-to-favourites",
//plugin name
name : "COOP to Server-Favourites",

init : function(instance){
this.ChangeCOOPtoFAV();
},

domchange : function(instance){
this.ChangeCOOPtoFAV();
},

// main-function
ChangeCOOPtoFAV : function()
{
// replace COOP with FAV
$("#main-loggedin-header-puff-coop").attr("data-href", "/bf3/servers/favourites/");
$("#main-loggedin-header-puff-coop > .main-loggedin-header-puff-content > .wfont").html("favourites");
// hide COOP counter
$("#main-loggedin-header-puff-coop > .main-loggedin-header-puff-content > .main-loggedin-header-puff-play").hide();

}
});


When i now add the language specific code (see below) it doesn't work.

BBLog.handle("add.plugin", {
//plugin ID
id : "coop-to-favourites",
//plugin name
name : "COOP to Server-Favourites",
// language strings
translations : {
"en" : {
"lang.fav" : "favourites"
},
"de" : {
"lang.fav" : "favoriten"
}
},

init : function(instance){
this.ChangeCOOPtoFAV();
},

domchange : function(instance){
this.ChangeCOOPtoFAV();
},

// main-function
ChangeCOOPtoFAV : function()
{
// replace COOP with FAV
$("#main-loggedin-header-puff-coop").attr("data-href", "/bf3/servers/favourites/");
$("#main-loggedin-header-puff-coop > .main-loggedin-header-puff-content > .wfont").html("lang.fav");
// hide COOP counter
$("#main-loggedin-header-puff-coop > .main-loggedin-header-puff-content > .main-loggedin-header-puff-play").hide();

}
});


Plugins still works, but the button title is "lang.fav".
Can anyone tell me what i forgot?

Thanks in Advance!

GosuSan
...html(instance.t("lang.fav")); // hide COOP counter
Post edited 1 x times, last by
And also need to

instance.ChangeCOOPtoFAV(instance);
Post edited 6 x times, last by
Topicstarter
Thanks for your reply!

I am soory, i'm still new to JS developing i have another question.

I understand this:
...html(instance.t("lang.fav")); // hide COOP counter

But what does this?
instance.ChangeCOOPtoFAV(instance);

And where do i have to put it in the sourcecode?

Sry for my bad english, it's not my native language.

EDIT: This is the full code:
DELETED


GosuSan
You have to change this
init : function(instance){
this.ChangeCOOPtoFAV();
},
domchange : function(instance){
this.ChangeCOOPtoFAV();
},


to this

init : function(instance){
instance.ChangeCOOPtoFAV(instance);
},
domchange : function(instance){
instance.ChangeCOOPtoFAV(instance);
},


That you have "instance" available in your custom function.
Post edited 1 x times, last by
Topicstarter
Ah ok, thank you very much for the fast support.

I think i'll release the plugin tomorrow.

I first want to look into the code of some other plugins to learn more about this language
and the bblog plugin system.

Thanks again

GosuSan

EDIT: another question: is it hard to create a button in the bblog-menu to enable / disable this little plugin?
It is not really needed, but i wonder how to do this.
See the example plugin...
it describes all whats possible.
You can also add it to your plugin list to see what it is doing.

http://getbblog.com/plugins/example.js
Topicstarter
Thanks, this helped me a lot!
You can close this thread if you want, at the moment all my questions are answered.

And many thanks to the whole bblog team, it's a great work you are doing here!

GosuSan