The ASP.NET ScriptManager control has the ability to provide localization for your scripts in several ways.
If your script is embedded in your assembly as a resource using the WebResourceAttribute attribute , then you can use the ScriptResourceAttribute to let the ScriptManager know that you have some localized lines stored in the .resx file somewhere you want it to be- Someday your script served. These lines are entered into the page as a JSON object, and then basically the script displays links to the JSON object, and not to literary lines.
For example, you would embed your script as follows:
[assembly: System.Web.UI.WebResource("ProjectNamespace.MyScript.js", "application/x-javascript")] [assembly: System.Web.UI.ScriptResource("ProjectNamespace.MyScript.js", "ProjectNamespace.MyScriptResources", "Messages")]
"ProjectNamespace.MyScript.js" is the full path to the embedded resource that is your script. In ScriptResourceAttribute, the second parameter is the full path to the embedded .resx file (minus the .resx extension) containing all localized messages. You consider it just like any other .resx, so you will have MyScriptResources.resx for the default culture, then MyScriptResources.es-MX.resx for Mexican Spanish will override, etc. The final parameter in the ScriptResourceAttribute is the name of the JSON object to be generated.
In the script, you reference the JSON object:
function DoSomething() { alert(Messages.ErrorMessage); }
In the above snippet, "ErrorMessage" is the name of one of the string resources in the .resx file.
If you embed a script, reference it from the ScriptManager using a tag that indicates the assembly and name.
Alternatively, you can store fully localized copies of the script , such as "MyScript.js", "MyScript.es-MX.js", "MyScript.en-UK.js", "etc., where the localized logic and messages are hard-coded directly into the script.
If you do this localization method, access it from ScriptManager using a parameter specifying the path.
There is a really good review and links to detailed step-by-step instructions on this subject with code samples on MSDN.
Note that if you use ASP.NET MVC, the ScriptManager control does not actually work with it. In this case, you need to look at another solution, such as a jQuery plugin for globalization or a potentially custom ScriptManager replacement for use in MVC .