I'm not going to go through a step-by-step tutorial on how to setup a script localization example here because it's done very well on the AJAX.ASP.Net site. One thing that's missing there, though, is a firm understanding of exactly how script localization works under ASP.Net AJAX. Understanding a little about how it all works might also help you understand a few bits about what happens when things go wrong.
First, the basic concept: Script localization means building scripts so that they make sense to the culture of the person using them. It would be *nicer* if someone in Germany saw something in German instead of English, and if someone in France saw something in French instead of German. Localizing something means making it local for the user.
ASP.Net has a system for localizing web pages using a satellite-assembly paradigm where you can add individual language support as totally independent modules that are used when available, or else a default language is used. Now with the introduction of ASP.Net AJAX, the concept is shifting towards more client-centric web design for ASP.Net and therefore the breadth of localizing components is spreading off the server and to the client browser.
Second, the samples: The sample from Microsoft on the subject of localizating ASP.Net AJAX has you build a web site which looks like this:

Here you see a dropdown that says "English". You can also change the language of the page through the dropdown:

....."Okay", you'd say, "But how is this any different from localization in earlier versions of ASP.Net?" You're right. So far nothing has changed. However, if you try to click one of the buttons, you're going to execute a block of script code that produces this (if you're running under Italian):

The script that generated this (the script we wrote) looks like this:
function CheckAnswer()
{
var firstInt = $get('firstNumber').innerText;
var secondInt = $get('secondNumber').innerText;
var userAnswer = $get('userAnswer');
if ((Number.parseLocale(firstInt) + Number.parseLocale(secondInt)) == userAnswer.value)
{
alert(Answer.Correct);
return true;
}
else
{
alert(Answer.Incorrect);
return false;
}
}
...and THIS is where the ASP.Net AJAX stuff comes into play. Look at how the argument to the alert() method uses this mysterious Answer object to get the strings to use (Answer.Incorrect or Answer.Correct). The Answer object actually refers to a .resx or resource file you generated on the server to hold all the localized strings. How is the script referencing the file and how is it getting the right strings?
You tell ASP.Net AJAX to load the resources needed for a script by using a Web and ScriptResource attribute in your Assembly.XX file (.cs or .vb). Like this (in C#):
[assembly: System.Web.UI.WebResource("LocalizingScriptResources.CheckAnswer.js", "application/x-javascript")]
[assembly: System.Web.UI.ScriptResource("LocalizingScriptResources.CheckAnswer.js",
"LocalizingScriptResources.VerificationResources", "Answer")]
You see here that you make a reference to the javascript file CheckAnswer.js in the first attribute as a WebResource. You then make a reference to a resource needed to localize the script via the ScriptReference (the second attribute). In the second attribute you reference a resource for the script with the name VerificationResources on the server, and refer to it as "Answer" on the client. As it turns out, I have two resource files on the server:
VerificationResources.it.resx
VerificationResources.resx
...Or the resource for the Italian and default culture, respectively. When the ASP.net AJAX framework is building the script to return to the client (either as a result of the first page load or a partial postback), it will look at the culture for the calling thread on the server and reference the resource files using the standard ASP.Net 2.0 methodology. It will take all of the resource data out of the resource file it grabs (VerificationResources.it.resx if the thread is running under the Italian culture, or VerificationResources.resx if anything else), package it up as a javascript type and return it to the client. On the client, it is given the name "Answer" in this sample, where the client code can reference it.
A look in fiddler will show an example of the "Answer" class generated for the default culture:
Answer={
"Verify":"Verify Answer",
"Correct":"Yes, your answer is correct",
"Incorrect":"No, your answer is incorrect"
};
If you reload the page and have it generate an Italian page, the fiddler dump will show the following amongst everything else that comes down:
Answer={
"Verify":"Verificare la risposta",
"Correct":"Si, la risposta e’ corretta",
"Incorrect":"No, la risposta e’ sbagliata"
};
When this block gets downloaded, it will change the contents of the type referenced by your script code. This is how localization works under ASP.Net.
Recommended reading:
