Best way to Localize .NET Web Application (Both Server-Side and Client-Side)

GIJOEROCK

New Member
In the past few days i have be implementing Localization for my web-application written in MVC.There are 3 main task that brake-down the Lozalization "Problem" that I could point out:[*]Storage: Store Key-Value pair of strings in multiple languages to be used in your application[*]Server-Side Access: Access the Value according to a given Key in your Server Side Script (e.g. Views, Controllers, Web-forms etc...)[*]Client-Side Access: Access the Value according to a given Key in your client Side Script (e.g. Java-script)[*]create a culture switching mechanism.There are several methods to accomplish each task that I have explored and I'm struggling with choosing between them.There are two questions that I'm interested in:[*]I would like to know what would be the best practice for localization? from your point of view.Please write Advantages\ Disadvantages for one method vs. the other.[*]Are there other methods or enhancements that you could suggest.1. StorageResource Files:
  • Store Key-Value pairs of localized strings in a resource file
  • Create a resource file with the same keys for each culture, e.g. myString.resx, myStrings.he-IL.resex etc...
XML Files:
  • Create a structured XML file that will contain a parent node for each key and childe nodes for each culture specific value e.g. \[code\]<string key="myAppName"> <heIL>some Hebrew value</heIL> <enUS>some English value</enUS></string>\[/code\]
2. Server Side Access
  • With both Storage options it would be fairly easy to get access to from the server side.
    • Using resource files a bit easier in that case becuse there are classess that are auto-generated to facilitate access to the values. So you use resources as regular clasess with static properties to access each string value according to a key.
    • With XML files you will have to write down the Access Layer code yourself, which is not necessarily a bad thing - because you get much more control that way (only if you need it)
3. Client Side AccessHere is where it gets interesting and sometimes complicated.There where two options that i have explored here and I'm not sure how to proceed. Server-Side Generated Script:
  • In your View\ Web-Form add a server script render block inside a \[code\]<script>\[/code\] tag
  • From this point dynamically create an Array of keys, or static variables in java script and place the required string inside them.Here is an example using Razor engine.\[code\] <script type="text/javascript"> k_CultureInfo = "@CultureInfo.CurrentCulture.Name"; K_ApplicationName = "@MyStrings.SomeStringKey"; .... </script>\[/code\]
Custom HTTP Handler:I found the idea in a blog pos here: Localize text in JavaScript files in ASP.NET Here
  • Bestially your write an HTTP handler that handles any ".js.axd" request comes to the server.
  • The "ScriptTranslatorHandler" will read the javascrip file and wil replace any instance of a predefined token e.g. Translate(SomeStringKey) in your java script to the correct string taken by any of the methods described above.
 
Back
Top