views:

286

answers:

10

In the US, you use a "." as the separator, but in Germany you use a ",". I'm trying to test whether my logic is smart enough to handle either one but I seem to be failing to put my Windows 2000 machine into German mode.

I went to Control Panel, Regional Options, and changed "Your locale" to "Germany". I then restarted both IIS and SQL Server. But my changes don't seem to have taken effect.

These lines still show "." to be the separator.

System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo( System.Threading.Thread.CurrentThread.CurrentCulture.Name);

Response.Write(ci.NumberFormat.NumberDecimalSeparator);

What am I doing wrong?

A: 

I think what you're after is the Formats tab (the first one there).

Dmitri Nesteruk
There is a "Numbers" tab and it is showing my "Decimal symbol" to be ",".So the control panel looks right, but ASP.NET still thinks it is US. Is there another place I need to be changing?
Corey Trager
A: 

You could set your current culture to be German.

I think it would be easier than switching your regional settings

Nathan Koop
+3  A: 

When you set your Regional Settings, did you make sure to "Apply all settings to the current user account and to the default user profile" (Advanced tab) ?

That should do it in most cases. I'm also assuming that your culture is not preset to "en-us" in the globalization element of Web.config.

It appears that you don't want to do it by setting your Culture settings manually in code, rather you want them inherited by System settings. That, IMO, is a good way of checking since your changes should be propagated to SQL server as well.

Cerebrus
No such thing on my W2K machine.
Corey Trager
Oops! I missed the part about W2K. Mine is XP SP2. However, there should be a way to apply all settings even on Win 2K. Lemme look it up.
Cerebrus
+1. On W2K I think you have to edit the registry manually to change the default profile's regional settings: look at HKEY_USERS/.DEFAULT/Control Panel/International. But it's easier just to add a globalization element to web.config.
Joe
Thanks for that helpful info, Joe! (and the vote) ;-)
Cerebrus
A: 

If you really want to hit this one...Virtual Machines are your friend. But you really need an msdn subscription to get the german version of an os.

Load an os (WinXP or Vista) into a virtual machine, then browse to the web site.

Chris Brandsma
A: 

I don't think IIS uses the region setting. You need to set the CultureInfo explicily in your code.

Dave Swersky
A: 

If you're just testing the one time, you could change the line to read this:

System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("de-DE");

and change it back afterwards. You could use strings like that if you want to do a bunch of unit tests.

Jeramy Rutley
+5  A: 

The best way to test this is to add a globalization element to your web.config, e.g.:

<system.web>
   <globalization culture="de-DE" uiCulture="en-US" />
</system.web>

Changing culture to de-DE will affect date and numeric formats: you could also change uiCulture if you want, leaving uiCulture as en-US means you will get exception messages in US English.

Joe
It worked. Thanks.
Corey Trager
+1  A: 

It's usually the wrong thing to make a website's handling of formatting issues like the decimal separator dependent on the locale of the web server. This adds a server configuration issue which can make it harder to deploy your app, whilst not actually necessarily giving the end user what they want. For example you might want to install a French and an English deployment of the same app to a single (Canadian!) server.

It's also quite common for the system locale to be set to something inappropriate due to legacy issues (eg. apps that only work in Japanese, or production servers all over the world running en-US as the ‘canonical version of Windows’).

It's normally better to handle this in the application layer, having either one locale option per deployment of your site code, or (if necessary) one locale option per user of the site. Then anyone can log in to the app and get the appropriate number formatting.

Finally, if your app's interface is exclusively English, it may be more appropriate to stick with the English number formatting anyway. Germans will have got used to this; it could actually be more confusing to have a mixture of English and German UI conventions together. IMO: Localise thoroughly, or not at all.

bobince
A: 

Can I just clarify something, you want to put your machine into German mode to test your web application, which just happens to be running on the same machine as the browser?

When this is running for real can we assume that the sever could be hosted outside Germany (or maybe in Germany but on a machine set up with a US locale - it happens a lot). If so setting the culture on the server isn't really what you want, and you probably won't be able to do that when you deploy anyway.

You also have another problem, there is no fool-proof way you can detect which culture your user wants to use. You can detect all sorts of info from the HTTP headers, do a domain lookup on the IP address, but what if a German speaker wanted to use your site from the US, or an American was in Germany and wanted to see "." and not "," for the decimal separator?

To put it another way, I am saying it doesn't matter what culture your client's PC is using - it is not relevant because once you go over the web all bets are off - even if your app did detect your culture correctly it might not be what your user wants!

So, the way I would do this is to ask the user what language they want and then explicitly set the locale in your application at run time. This does mean asking the user to pick a langague but it's the only way to be sure of using the right locale for the user. If all your users are German then you don't have to ask, you can just hard code it. If his approach sounds like it might work then there's some good sample code here: http://msdn.microsoft.com/en-us/library/bz9tc508.aspx.

Good luck, or rather Viel Glück!

Steve Haigh
A: 

Here is an article

Easily Test Your Code For Multiple Cultures

http://haacked.com/archive/2007/06/14/easily-test-your-code-for-multiple-cultures.aspx

silverfighter