Skip to main content
Klaus Göbel
Legend
December 5, 2021
Answered

Changing text of "confirm"

  • December 5, 2021
  • 2 replies
  • 791 views

When using "confirm", the text is displayed in the language
which is selected in the system setting:

var Input = confirm("Header",1,"Message");

But there is no way to translate the text by myself.

"$.locale" also doesn't work.

 

Has anyone found a way to do this?

This topic has been closed for replies.
Correct answer 4everJang

Klaus, here is a replacement for the global confirm( ) that does what you need. Of course you can also set the local strings for 'Yes' and 'No' in some global object and adapt the code so you do not have to pass the strings every time.

 

MyConfirm = function( sPrompt, bDefault, sTitle, sYes, sNo )
{
	var oDlg = new Window( 'dialog', sTitle, [0,0,200,100] );
	oDlg.add( 'statictext', [30,30,170,45], sPrompt );
	var btnYes = oDlg.add( 'button', [50,60,90,80], sYes );
	var btnNo  = oDlg.add( 'button', [110,60,150,80], sNo );
	if( bDefault )
	{
		oDlg.defaultElement = btnNo;
	}
	else
	{
		oDlg.defaultElement = btnYes;
	}

	var bResult = false;

	btnYes.onClick = function( )
	{
		bResult = true;
		oDlg.hide( );
	}

	btnNo.onClick = function( )
	{
		oDlg.hide( );
	}

	oDlg.center( );
	oDlg.show( );
	
	return bResult;	
}

 The only thing missing compared to the confirm( ) function is the question mark icon. You should be able to add that if you need it. 

2 replies

4everJang
4everJangCorrect answer
Legend
December 6, 2021

Klaus, here is a replacement for the global confirm( ) that does what you need. Of course you can also set the local strings for 'Yes' and 'No' in some global object and adapt the code so you do not have to pass the strings every time.

 

MyConfirm = function( sPrompt, bDefault, sTitle, sYes, sNo )
{
	var oDlg = new Window( 'dialog', sTitle, [0,0,200,100] );
	oDlg.add( 'statictext', [30,30,170,45], sPrompt );
	var btnYes = oDlg.add( 'button', [50,60,90,80], sYes );
	var btnNo  = oDlg.add( 'button', [110,60,150,80], sNo );
	if( bDefault )
	{
		oDlg.defaultElement = btnNo;
	}
	else
	{
		oDlg.defaultElement = btnYes;
	}

	var bResult = false;

	btnYes.onClick = function( )
	{
		bResult = true;
		oDlg.hide( );
	}

	btnNo.onClick = function( )
	{
		oDlg.hide( );
	}

	oDlg.center( );
	oDlg.show( );
	
	return bResult;	
}

 The only thing missing compared to the confirm( ) function is the question mark icon. You should be able to add that if you need it. 

Klaus Göbel
Legend
December 6, 2021

Hi Jang,

 

thanks a lot!!!

 

 

4everJang
Legend
December 5, 2021

I assume you refer to the 'Yes' and 'No' buttons. If the user has a certain locale set they would want to have that used in such dialogs, right ? There is of course a way around this by creating your own dialog and adding your own buttons. But the built-in dialogs are supposed to use the system locale.

Klaus Göbel
Legend
December 5, 2021

This is what I expected and feared

4everJang
Legend
December 5, 2021

So what is the use case ?