Skip to main content
Klaus Göbel
Legend
Dec 5, 2021 4:03 PM UTC
Answered

Changing text of "confirm"

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 is closed to new replies. Start a new post to keep the conversation going.
4everJang
4everJangCorrect answer
Legend
Dec 6, 2021 2:04 PM UTC

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. 

10 replies

4everJang
4everJangCorrect answer
Legend
Dec 6, 2021 2:04 PM UTC

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. 

Translate
Klaus Göbel
Legend
Dec 6, 2021 2:06 PM UTC

Hi Jang,

 

thanks a lot!!!

 

 

Translate
4everJang
Legend
Dec 5, 2021 4:43 PM UTC

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.

Translate
Klaus Göbel
Legend
Dec 5, 2021 4:48 PM UTC

This is what I expected and feared

Translate
4everJang
Legend
Dec 5, 2021 4:49 PM UTC

So what is the use case ?

Translate