Monday, November 14, 2011

Use ASP.NET Resource strings from within javascript files

It seems to be a common issue.

ASP.NET allows you to use resource files (*.resx) to localize content of pages (or views, if we are in context of ASP.NET MVC). All what you need is to put resource files under ~/App_GlobalResources folder and use either resource expression or  HttpContext.GetGlobalResourceObject() API to get a proper string. It is well documented on MSDN. The only issue - this API is not accessible within static resources such JavaScript files.