How to localize buttons in .js file

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
Hi,

I am new to MVC, right now I am trying some modification to NopCommerce V2.4

While customer add some product in their cart by pressing "Add To Cart" button we will display a dialog having some message and two buttons
1-Go To Cart
2-Continue Shopping

These buttons are from some .js file, I want apply locatization to these button text.

Any Help in this regard will be highly appreciated.

Here is .js code snippet


if(response.success)
                {
                    if(this.cartType == 'addtocart')
                    {
                        jQuery( "#addtocart-confirm" ).html(response.message);
                        jQuery( "#addtocart-confirm" ).dialog({
                      resizable: false,
                      height:140,
                      modal: true,
                            title:response.title,
                      buttons: {
                        "Go to cart": function() {
                          jQuery( this ).dialog( "close" );
                                    if(response.returnUrl)
                                    {
                                        location.href = response.returnUrl;
                                    }
                                    else
                                    {
                                        location.reload(true);
                                    }                            
                                 },
                        "Continue shopping": function() {                      
                          jQuery( this ).dialog( "close" );
                                          location.reload(true);
                        }
                      }
                    });
                    }
12 years ago
Here is what I do.

1. Add your locale string resource to the database.
2. Pull the value in your action method.
3. Create a JSON View Model and include the resource as part of your model.
4. Return JSON result from your action method (e.g. return Json(myModel, "JsonRequestBehavior.AllowGet").
5. On success in your .ajax call map your resource from the JSON object to your button.

That's it!  Hope this helps.
12 years ago
Thanks for the reply.

I am not sure how to do that for the last point:
5. On success in your .ajax call map your resource from the JSON object to your button.

If I tried to name the button on the fly from response.buttontext  instead hard coded "Go to cart", It will break the functionality, in other words it did't work.

any suggestions ?

buttons: {
                        "Go to cart": function() {
                          jQuery( this ).dialog( "close" );
                                    if(response.returnUrl)
                                    {
                                        location.href = response.returnUrl;
                                    }
                                    else
                                    {
                                        location.reload(true);
                                    }                            
                                 },
                        "Continue shopping": function() {                      
                          jQuery( this ).dialog( "close" );
                                          location.reload(true);
                        }
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.