I think I need some guidence in general Localization and Globalization in ASP.NET MVC3. I am not even sure what both of these mean and if really need both.
This is what I have for now. MVC3 application, one Resources.resx file where I keep my strings and in the Views I am using these strings as @MyApplication.Web.Properties.Resources.MyString
and I am using them in the Data Annotations for the Models as [Required(ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = "RequiredField")]
I need these string in Controllers now. I have found a reference on MSDN and tried using them as
ResourceManager rm = new ResourceManager("Strings", Assembly.GetExecutingAssembly()); and rm.GetString("InvalidFormData").
But like this I get:
Could not find any resources appropriate for the specified culture or the neutral culture. Make sure “Strings.resources” was correctly embedded or linked into assembly “MyApplication.Web” at compile time, or that all the satellite assemblies required are loadable and fully signed.
What I want to have is one application that would be hosted on different domains for different languages. I would create multiple Resource.resx files. So I don’t need to handle multiple languages in one deployment. I want to set the language for each one manually (in web.config I guess).
Can someone please explain to me what am I missing and what do I need to accomplish my goal? Or, perhaps, if you know any good references, just point me to them.
Thank you.
I have found the way to do what I wanted. To mention once again, I want to manually set the language of the application with no concern of the users browser culture. I just wanted to have the same code that will cater for multiple languages cause the application will be hosted on different domains for different countries in their own languages.
The solution is to have:
In Global.asax
In the Views:
In the Model:
In the Controller:
And then create the
Resource.resxfiles like:That’s it. Very simple.