Web.config setting for UseCultureOverride does not take effect

This is a place to discuss how to adapt mojoPortal to the needs of different cultures. Before asking questions here please first review the localization documentation.

This thread is closed to new posts. You must sign in to post in the forums.
1/7/2010 9:45:30 PM
Gravatar
Total Posts 31
There are 10 kinds of people in the world, those who know binary, and those who don't

Web.config setting for UseCultureOverride does not take effect

I have added the following to web.config to override the thread culture of the site but it does not take effect, the browser setting is still used:

<add key="UseCultureOverride" value="true" />

<!-- First site shall always be in English -->
<add key="site1culture" value="en-US" />

<!-- Site ID=6 shall be zh-CHT -->
<add key="site6culture" value="zh-CHT" />

<!-- Site ID=7 shall be zh-CHS -->
<add key="site7culture" value="zh-CHS" />

There are no overriding settings in user.config for these keys. Note: I am using <add key="UseRelatedSiteMode" value="true" />, if it helps.

Any directions on how to diagnose?

1/8/2010 6:34:42 AM
Gravatar
Total Posts 18439

Re: Web.config setting for UseCultureOverride does not take effect

Hi,

For any settings in the <appSettings section of Web.config, you should never modify them or add them in Web.config, you should put custom settings in user.config where you will not lose your custom changes. Web.config has default settings, and you put your overrides in user.config.

Web.config already had a setting <add key="UseCultureOverride" value="false" />, so you should not add a new copy of it, the one that lives lower in the file wins in this case, so if you added it above the existing setting it would have no effect.

We do not add overrides for you in user.config except for a few special cases where default have changed and for backward compatibility we left the old defaults in Web.config but added overrides in user.config so new sites will use the preferred new settings by default.

For more info see Web.config Guide.

Hope it helps,

Joe

1/9/2010 7:36:18 AM
Gravatar
Total Posts 31
There are 10 kinds of people in the world, those who know binary, and those who don't

Re: Web.config setting for UseCultureOverride does not take effect

Thanks Joe, good point and I moved the settings to user.config instead.

Unfortunately the different sites still use the browser setting. It just seems like culture override is not enabled. I even restarted the web server. So all sites are using resource files which are English.

Is there any other setting that may prevent culture override from working?

1/9/2010 10:14:54 AM
Gravatar
Total Posts 18439

Re: Web.config setting for UseCultureOverride does not take effect

It works in my testing. Keep in mind that when you add settings to user.config it does not detect changes to the user.config file automatically like it does for Web.config, so you must touch the Web.config after that to make it reload settings. ie type a space in Web.config and save it.

Hope it helps

Joe

1/9/2010 11:09:40 AM
Gravatar
Total Posts 31
There are 10 kinds of people in the world, those who know binary, and those who don't

Re: Web.config setting for UseCultureOverride does not take effect

I know, I am sure that other settings take effect in both web.config and user.config but not so for culture.

Actually, after some research I figured out the problem. It was more subtle than which config file, etc. There is a CultureHelperHttpModule.cs implementation that reads the culture setting. It is very straightforward. However you catch all exceptions without logging when overrideing CurrentThread so we do not know if anything special happened. I have the module definition set like this, like the default:       <add name="CultureHelperHttpModule" type="mojoPortal.Web.CultureHelperHttpModule, mojoPortal.Web" /> so surely this module runs on page load.

When I was investigating this I noticed something odd in the Performance viewer on the server. Every time I request or refresh a web page from a site which is forced to non-English the performance counter "# of Exceptions" increases by one. However, as soon as I set UseCultureOverride to false, there is no such exception registered in the performance counter!

Just for fun, I then set all culture overrides to ja-JP. Then, there were no exceptions, and all resources were displayed correctly in Japanese!

It seems that the problem arised since I used zh-CHS and zh-CHT. Instead of zh-CHT I switched to use zh-HK, which worked properly for Traditional Chinese override. I also changed to zh-CN instead of zh-CHS which worked properly for Simplified Chinese.

There is an interesting note on MSDN saying: "The CultureInfo..::.CreateSpecificCulture method throws ArgumentException for the neutral cultures "zh-Hant" ("zh-CHT") and "zh-Hans" ("zh-CHS"). " Perhaps this happens in the application now, but the exception is swallowed. See:
http://msdn.microsoft.com/en-us/library/system.threading.thread.currentuiculture.aspx 

You can check in your own test, if you force the site culture to zh-CHT and zh-CHS, I would be surprised.

Since the resource files are called zh-CHT and zh-CHS it might be worth pointing out that these cannot be used as override cultures for a site.

1/12/2010 6:48:24 AM
Gravatar
Total Posts 18439

Re: Web.config setting for UseCultureOverride does not take effect

Thanks for that info.

I've added a check to make sure we don't try to assign a neutral culture to the thread and I've added logging of any swallowed errors.

I've also added logic so that if a neutral Chinese culture is specified it will automatically use a specific one

if (cultureName == "zh-CHS") { cultureName = "zh-CN"; }
if (cultureName == "zh-CHT") { cultureName = "zh-HK"; }

This makes sense because we only have resources for zh-CHS and zh-CHT and this will make it use those correct resources even though it requires setting the culture to a specific culture rather than the neutral culture it still uses the same .zh-CHT.resx file if the setting is specified as zh-CHT since we don't have a specific .resx file for .zh-HK.resx

Best,

Joe

You must sign in to post in the forums. This thread is closed to new posts.