One way is for you to define these strings in your layout, for example in the <head>
tag:
<head>
<script>
var DISPLAY_OLA = "@Resources.DISPLAY_OLA";
</script>
</head>
But that is not so elegant. So another way is you create a dynamic external script, as explained in this link , which summarizes:
You create a Resources.js.cshtml
view. In this view you create all the resources you need, in the same way as I showed above. Then refer to the script tag:
<script src="@Url.Action("ResourcesJS")"></script>
So with variables declared globally, you can access them in any script. Often it is not recommended to use global variables, but I think in this case it is useful. What you can do is create the resources in a single object (which is how I do it 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.