Visual Studio 2010 doesn't generate Resource (Resx) designer code if file is localized

Aerendel picture Aerendel · Aug 17, 2012 · Viewed 14.2k times · Source

I've just come across the weirdest behavior in Visual Studio 2010 while working with Resx resource files and I just can't wrap my head around it.

The problem is as follows: Visual Studio will not generate the designer.cs file for a resource file with a localized name (such as resource.fr.resx), but it works fine for other files with simple names (such as resource.resx).

Here's a snapshot of my visual studio project setup:

enter image description here

As you can see I just did a simple test with 3 resource files:

  • test.resx
  • test2.resx
  • test.fr.resx

The designer.cs files for test.resx and test2.resx are generated just fine. However test.fr.designer.cs is created but always blank, no matter what I do.

I have double and triple checked: the custom tool property is properly set for the localized file. All properties are exactly the same across all files (I'm using PublicResxFileCodeGenerator, but I get the same behavior if I set access modifier to internal and use ResxFileCodeGenerator).

Note: I've noticed that when created a resource file, Visual Studio normally defaults the access modifier to "Internal". However, when creating a localized resource file (resource.fr.resx) it defaults to "No code generation". Just found that interesting to note since it proves that visual Studio is treating the localized file differently for some reason.

--> Is there something I'm missing here? I would appreciate if anybody has some insight on the subject, this is driving me crazy.

Answer

Larry picture Larry · Aug 17, 2012

While I haven't looked into this particular issue, I've had numerous other problems with ".resx" files. Visual Studio is sometimes buggy (handling ".resx" files among other things), and I've officially reported some of these to MSFT (since it affects my own commercial localization program). In any case, you shouldn't normally be naming things this way. It effectively violates MSFT's localization rules. Default language files shouldn't normally have an embedded language code, and it could be choking on it for this reason. I'd need to investigate, but what you should be doing is creating "Test.resx", which has a "Designer.cs" file, and then "Test.fr.resx", which doesn't. All default language strings are then placed in "Test.resx" and the corresponding French strings in "Test.fr.resx". In code, you then access the strongly typed name found in "Test.Designer.cs", and the string you get back will be the default language string unless you set "System.Threading.Thread.CurrentThread.CurrentUICulture" to "fr". You'll then get back the French version of the string from "Test.fr.resx", unless it's not found there (there's no translation), in which case you'll get back the fallback string from "Test.resx" (i.e., the default language string). This is how the hub-and-spoke model basically works.