Using resource files (.resx) in javascript

I am trying to use localization in my project, but I cannot find a way to access my resx files from javascript. I looked around a bit, and I don’t think that the “AJAX call” method would be ideal for my project, since I have a lot of strings to extract and just need to spam the server!

If I just put it in my HTML, it will work with this code:

@using Resources
<p>@Html.Raw(ISt_Localization.January)</p>

I guess one of the things I could do is put all the lines in a hidden div and then get the contents from the div in my javascript, but that will not be very efficient.

+5
source share
2 answers

, , javascript, , . javascript. .

:

var Resources = {
        January : "@Html.Raw(ISt_Localization.January)",
        February : "@Html.Raw(ISt_Localization.February)",
        ...
};
+3

:

@using Resources

<script>
var value = '@Resource.January';
/* work with value 
.......
.....

*/
</script>
+3

All Articles