Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with language specific resource files in a class library project

I'm working on an ASP.NET MVC 2 application and use a seperate class library for my model. I used resource files in my class library project to embed validation messages and use it in my meta data classes and everything was Ok till I decided to add a new language to my project so I renamed Resource.resx to Resource.en-US.resx and also copied and saved it as a new Resource.fa-IR.resx for another language but after renaming it, everything in Designer.cs companion file has been gone and I can't access Resource file anymore. As soon as I remove the language name (e.g. en-US) from filename it works properly.

I have already set Access Modifier to Public but no result.

I'm using Visual Studio 2008 SP1.

like image 481
Mahdi Taghizadeh Avatar asked Feb 06 '10 12:02

Mahdi Taghizadeh


1 Answers

Don't rename resources.resx: instead, just add resource files for the additional cultures you need.

Resources.resx contains the "neutral" resources which will be compiled into your main assembly, and used as a fallback if no satellite assembly for the required culture is located.

Each additional resource file, e.g. Resource.fa-IR.resx will normally be compiled into a culture-specific satellite assembly.

You can also add to your AssemblyInfo.cs the NeutralResourcesLanguageAttribute, which informs the ResourceManager of the language you have used for the neutral resources:

assembly: [System.Resources.NeutralResourcesLanguage("en-US")]
like image 79
Joe Avatar answered Sep 23 '22 02:09

Joe