0

I have an MVC app, in which to translate I am storing all the text fields in a .resx file and then retrieving them with:

Resources.Resource.FirstName}

I have a JavaScript file which I need to do the same for two strings. I have checked Google and saw the JQuery.Globalization library (which doesn't seem to be available anymore) but that is way overkill for just two strings. I need to translate the two "Please wait..." strings in the following. How doo I do this easily?

$("#the_button").lockSubmit({
        submitText: "Please wait..."
    });

    $(".the_button").lockSubmit({
        submitText: "Please wait..."
    });

1 Answer 1

1

The easiest way is to define global js variabe in head section of html in layaout:

...
<script>
    var translation = {
        submitText: "@Resources.Resource.SubmitText"
    };
</script>
...

and then use this in js script

...
$("#the_button, .the_button").lockSubmit({        // you can use multiple selector here
    submitText: translation.submitText
});
...

You can also use html data-* attribute:

...
<button id="the_button" data-submit-text="@Resources.Resource.SubmitText" >Button</button>

and js file:

...
$("#the_button").lockSubmit({
    submitText: $("#the_button").attr("data-submit-text");
});
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.