I have a jQuery function that changes the name in all .task-row classes. How can I change the local place of the title Title to the place of translation. From such

$('.task-row').attr('title', 'Edit'); 

on such

 $('.task-row').attr('title', '@Shop.Resources.Properties.Literals.Edit'); 
  • on the client - no way. @Shop.Resources.Properties.Literals.Edit is ASP.NET Razor? - Igor
  • $('.task-row').each(function(){$(this).attr('title', i18n($(this).attr('title'), locale))}) - vp_arth
  • @Igor, why not? Can create service and load AJAX from server. When loading a page, you can create a couple of variables and read them already - Vadim Prokopchuk
  • Ask how you know which variable to load? data- attribute of an element to help) - Vadim Prokopchuk
  • @Igor Yes, this is Razor. - Maksims

1 answer 1

As we found out, @Shop.Resources.Properties.Literals.Edit is ASP.NET Razor.

If this code is in View, then it will work. If the code is in the js file, then it is, of course, incorrect, since the js files are sent by a separate request and Razor are not processed.

If you pass this text to the client along with the page there is no possibility, you can request it using $.ajax .

Still there are options with libraries like the @ vp_arth i18n mentioned above.

https://github.com/wikimedia/jquery.i18n