Best practice for ASP.NET MVC resource files

You should avoid App_GlobalResources and App_LocalResources. Like Craig mentioned, there are problems with App_GlobalResources/App_LocalResources because you can’t access them outside of the ASP.NET runtime. A good example of how this would be problematic is when you’re unit testing your app. K. Scott Allen blogged about this a while ago. He does a good job of … Read more

How to get the comment from a .resx file entry

You should be able to get Comment via ResXDataNode class: http://msdn.microsoft.com/en-us/library/system.resources.resxdatanode.aspx You will need to set UseResXDataNodes flag on the reader: http://msdn.microsoft.com/en-us/library/system.resources.resxresourcereader.useresxdatanodes.aspx

Access resx resource files from another project

Resource expressions (<%$ Resources: ClassKey, ResourceKey %>) use ResourceExpressionBuilder class behind the scene. This class can lookup global and local resources only (in website’s App_GlobalResources and App_LocalResources folders). Instead, you can use CodeExpressionBuilder class to access resources from different project. Here’s how to use it. Add CodeExpressionBuilder class to App_Code folder: using System.CodeDom; using System.Web.Compilation; … Read more

Localize Strings in Javascript

A basic JavaScript object is an associative array, so it can easily be used to store key/value pairs. So using JSON, you could create an object for each string to be localized like this: var localizedStrings={ confirmMessage:{ ‘en/US’:’Are you sure?’, ‘fr/FR’:’Est-ce que vous ĂȘtes certain?’, … }, … } Then you could get the locale … Read more

What are the benefits of resource(.resx) files?

Resource files give you an easy way to localize/internationalize your .net applications by automatically determining which language resx file to use based on the user’s locale. To add more languages, simply add another translated resource file. Resource files give you a central location to store your strings, files and scripts and refer to them in … Read more

Modifying .resx file in C#

There’s a whole namespace for resource management: System.Resources. Check out the ResourceManager class, as well as ResXResourceReader and ResXResourceWriter. http://msdn.microsoft.com/en-us/library/system.resources.aspx I managed to lay my hands on a very old debug method that I used to use at one point when I was testing some resource related stuff. This should do the trick for you. … Read more

DisplayName attribute from Resources?

If you use MVC 3 and .NET 4, you can use the new Display attribute in the System.ComponentModel.DataAnnotations namespace. This attribute replaces the DisplayName attribute and provides much more functionality, including localization support. In your case, you would use it like this: public class MyModel { [Required] [Display(Name = “labelForName”, ResourceType = typeof(Resources.Resources))] public string … Read more