Click here to Skip to main content
15,885,876 members
Articles / General Programming / Localization
Technical Blog

JQuery Localized Confirm Box

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
21 Nov 2015CPOL 4K   1  
A solution to localizing a jQuery dialog box

We were facing an issue that our french customers want confirm box with button captions in french, ie they want ok/cancel captions in french.

We had tried so much to localize the javascript confirm box, but we failed because the confirm box use the win32 api in internet explorer and some other craps in other browsers.

But we finally find one solution. The jQuery Easy Confirm Dialog plugin's

This is very simple and only we need is a style sheet and a jquery-ui.js.
 
The code is given below.

 HTML Page codes.

HTML
<head runat="server">
    <title></title>
       <link href="Styles/EasyConfirm.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/jquery-1.7.js" type="text/javascript"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js" type="text/javascript"></script>
   
     <script src="Scripts/jquery.easy-confirm-dialog.js" type="text/javascript"></script>
  </head>


 <asp:Button ID="ClickBtn" runat="server" Text="Click" OnClick="ClickBtn_Click" />
    <a href="#" id="yesno">Normal test with yes and no</a>
    <script type="text/javascript">
        $("#<%=ClickBtn.ClientID %>").easyconfirm({ locale: { title: '<%=TitleFor %>', text: '<%=Message %>', button: ['<%=CancelButton %>', '<%=OkButton %>']} });

        $("#<%=ClickBtn.ClientID %>").click(function () {          
                alert("You clicked yes");
          
        });   

The code behind is

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        public string TitleFor
        {
            get;
            set;
        }

        public string Message
        {
            get;
            set;
        }

        public string OkButton
        {
            get;
            set;
        }

        public string CancelButton
        {
            get;
            set;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            TitleFor = "Please Confirm";
            Message = "Do you agree ?";
            OkButton = "bonjour/ok";
            CancelButton = "Bonjour/Cancel";
        }

        protected void ClickBtn_Click(object sender, EventArgs e)
        {
          
        }
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
India India
I am a software developer with a passion to develop innovative ideas.

Comments and Discussions

 
-- There are no messages in this forum --