PDA

View Full Version : How to localize Yesno button in Ext 4.1 ?



new2extjs
15 Nov 2012, 2:38 AM
I want to localize the yes no text of button in extjs 4.1. I tried to change ext-lang-xx.js file but it doesn't work. Any suggestions please?

Farish
15 Nov 2012, 3:24 AM
Yes and No buttons for which component?

sword-it
15 Nov 2012, 4:07 AM
Hi new2extjs,


See this thread-

http://www.sencha.com/forum/archive/index.php/t-231440.html?

new2extjs
15 Nov 2012, 4:32 AM
I have this message.


Ext.Msg.show({
title: "test",
msg: "test",
buttons: Ext.MessageBox.YESNOCANCEL,
closable: true,
fn: function( ){

}
});

I want to localize the yes, no, cancel of buttons. I have modified the ext-lang-xx.js file by adding this:


Ext.MessageBox.msgButtons['cancel'].text = "test";
Ext.MessageBox.msgButtons['yes'].text = "test";
Ext.MessageBox.msgButtons['no'].text = "test";


But the change isnot reflected in the message box buttons. How can I resolve this?

Farish
15 Nov 2012, 4:53 AM
the way you are doing it is working in ExtJS 4.0.7 but not in 4.1.x. Change like this:



// Add this to your locale file; remove the lines which you have posted above! they were meant to be removed for ExtJS 4.1.x
if(Ext.MessageBox){
Ext.MessageBox.buttonText = {
ok : "TestOK",
cancel : "TestCancel",
yes : "TestYes",
no : "TestNo"
};
}

// Now you can create a message box like this in your app:
Ext.Msg.show({
title:'Messagebox Title',
msg: 'Are you sure want to delete?',
buttons: Ext.Msg.YESNOCANCEL
});

Farish
15 Nov 2012, 5:00 AM
the locale file has the following comments:


// As of 4.0.4, setting the buttonText above does not take effect properly. This should be removable in 4.1.0
// (see issue EXTJSIV-3909)

Because of an earlier issue, the following 4 lines were added below these comments (which are no longer needed for ExtJS 4.1.x:


Ext.MessageBox.msgButtons['ok'].text = Ext.MessageBox.buttonText.ok;
Ext.MessageBox.msgButtons['cancel'].text = Ext.MessageBox.buttonText.cancel;
Ext.MessageBox.msgButtons['yes'].text = Ext.MessageBox.buttonText.yes;
Ext.MessageBox.msgButtons['no'].text = Ext.MessageBox.buttonText.no;

new2extjs
15 Nov 2012, 5:27 AM
Thanks for the reply. I have removed those lines. But still the buttons yes, no , cancel are coming in English eventhough the message is coming in another language. Do I have to add something to the file where I have written the code for message or in some other file ?

Farish
17 Nov 2012, 1:26 AM
no you dont have to add anything else. Just remove those 4 lines and change the text in that object in the locale file. then you can just create a message box like this:



Ext.Msg.show({
title: "test",
msg: "test",
buttons: Ext.MessageBox.YESNOCANCEL,
closable: true,
fn: function( ){
}
});

Farish
17 Nov 2012, 1:29 AM
add this code in your app JS file before creating any message boxes and see if it changes anything:



if(Ext.MessageBox){
Ext.MessageBox.buttonText = {
ok : "TestOK",
cancel : "TestCancel",
yes : "TestYes",
no : "TestNo"
};
}

If this works, then there may be a problem in loading the locale file. It might not be loaded before the message box is being created...