views:

29

answers:

2

I am creating an ASP.NET web application in C#, and have to localize the application into English and French. I have created two resources files: App_GlobalResources\Resources.resx and App_GlobalResources\Resources.fr.resx containing the english and french content.

When I run the application with my browser set to French (fr_FR), the french content is correctly displayed in the markup.

Within the code-behind, when I access values from the resources, it returns the default english values only. e.g.

this.CompanyName.Text = string.Format(App_GlobalResources.Resources.CompanyLocationsFormat, companyName);

Debugging the app shows that the CurrentCulture and CurrentUICulture are both correctly set to fr_FR.

Can anyone explain how I can get the code-behind to use the culturally-appropriate resource file?

Many thanks

(C#, ASP.NET 3.5 SP1, Visual Studio 2008, IE 8.0.7600)

A: 

Are you certain that this specific resource (CompanyLocationsFormat) exists in the french resources file? If a resource is missing, it will fall back to the default one.

DanP
Hi Dan, yes, I've checked that this resource is in the french resources file. The problem is not confined to this single resource item - it is occuring for any resource value I try to access from within the C# code. In the bin directory, there is a /fr directory containing a .resources.dll file.I have noticed that the Resources.fr.Designer.cs file is empty - is this normal?
Jon
@Jon - That could be the issue; I'm not certainly how you're accessing the resources in the view, but that may use a different method than the strongly-typed wrapper that the designer creates around the resource file.
DanP
A: 

Do you have this in your <system.web> section in web.config?

<globalization culture="auto" uiCulture="auto" />
Antony Scott
Thanks Antony, I didn't have that in (though it was in the <%@Page %> directives on each page. I added it to the web.config, but it didn't make any difference.
Jon
have you got both resx files set to the same namespace?
Antony Scott
There doesn't look to be a namespace in the .resx files (apart from the www.w3.org namespace which is the same in both). Only the default resource has a .Designer.cs file - the .fr.resx has no C# code file.
Jon
in the properties of the resx (View | Properties) you can set the namespace.
Antony Scott