One way is you define these strings in its layout, for example in the tag <head>
:
<head>
<script>
var DISPLAY_OLA = "@Resources.DISPLAY_OLA";
</script>
</head>
But that’s not so elegant. So another way is you create a dynamic external script, as explained at that link, that summing up:
You create a view Resources.js.cshtml
. In this view you create all the Resources you need, just like I showed above. Then reference in the script tag:
<script src="@Url.Action("ResourcesJS")"></script>
Thus, with variables declared globally, you can access them in any script. It is often not recommended to use global variables, but I think in this case it is useful. What can be done is to create the Resources in a single object (which is how I do in one of the projects where I work):
var Lang = {
DISPLAY_OLA: "@Resources.DISPLAY_OLA"
};
Concentrating all Resources on the global object Lang
you have only one global variable.
Yes friend, but the variable content takes the string literally (as it is written in front of it) .
– Jedaias Rodrigues