Lempkin
Lempkin

Reputation: 1578

Localization with resource files not working

I have 2 resource files:

They both contain the key "BtnConnecter" with the French value in Resource.resx and English value in Resource.en-GB.resx. In my view I use @Resource.BtnConnecter.

My Chrome is set in French, my IE set in English, but I always see the French value.

(Note that I have another C# project with localization working. I have English values in IE, and French values in Chrome. The problem is not in the navigator configuration.)

What did I miss?

Upvotes: 2

Views: 5319

Answers (2)

Will Ray
Will Ray

Reputation: 10879

Have you modified your Web.config to support globalization? Specifically, the culture, uiCulture, and enableClientBasedCulture attributes.

<configuration>
    <system.web>
        <globalization fileEncoding="utf-8" requestEncoding="utf-8" culture="auto" uiCulture="auto" enableClientBasedCulture="true" />

More information about this attribute can be found in the MSDN documentation.

Upvotes: 3

Jeff
Jeff

Reputation: 2861

There's a few things to check: First, is your IE set to en-GB, or en-US (or just en)? You might try renaming your english resx to '.en.resx' instead. This would help because the resx files cascade. If it cannot find a resx file for 'en-US' when that is the language, it will look for 'en' before resorting to the default. So you would be better off with language-specific resx files instead of culture-specific ones.

Second, it is possible that you need to specify 'BtnConnecter.Text' in your resx file, not just 'Btn.Connecter'. This is because there are frequently multiple parts of a control that need globalization, so the format 'control.property' is used as the key, not simply 'control'.

Lastly, if you have a functional project that is working, I would compare the two. There may be a difference between them that needs to be fixed. I'd double-check the build-action property on your resx files and your 'Copy to Output Directory' property.

Upvotes: 0

Related Questions