Useful (?) Tip #3

.NET has great support for globalisation of code (why globalisation? Surely you’re actually regionalising it?) and that extends to web applications too. This piece of code lets your web application pick up the language preferences of the user’s browser, enabling you to pick up a localised set of strings and so on for them.
Stick it in the AcquireRequestState handler of Application in Global.asax.
Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(Me.Request.UserLanguages(0))
Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(this.Request.UserLanguages[0]);
…then whenever you get a string from your resource file, .NET will look for a localised version first and only load your default if it can’t find one.
In practical terms this means you can get country-specific messages in your web application:
[en] Please select a colour.
[en-US] Please select a color.
[en-AU] G’day mate. What cala d’ya want?
[fr] Selectez-vous une coleur. (or something like that. My French is not great)
I’ll show you how to get those strings to appear automatically tomorrow.
This entry was posted in Computers and Internet. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s