views:

144

answers:

1

This is related to my early post today: link text

So now I have demo winforms app with two different localizations, one english, one spanish. Now let's say I have a big app, let's say it supports localizations in 15 different languages. In the previous post, it was suggested that I add a few lines when the form is initialized to set the localization. Currently I'm using click once to deploy my application. I'm trying to find a way to deploy without having 15 different flavors of the app. Is there a way to look at the current user's localization and if it matches one of the languages I've written my screens in to use that, otherwise use the default?

+2  A: 

The built-in localization system of the .NET framework already handles this fallback situation. You just install the satellite DLLs that localize your forms and controls and then, if the right one matches the user's locale, .NET will use it, otherwise it will fallback to the next related parent locale. For example, if your application's default language is en-US but you have provided an en-GB translation and an en translation, then the fallback is:

en-GB->en->en-US

i.e. when en-GB is not available, it looks for en, and if that isn't there it uses the default, en-US.

Therefore, when distributing, you can distribute just your main en-US application and then provide additional satellite DLLs for particular languages as, say, language packs. There is an attribute, SatelliteContractVersionAttribute, that allows your main application assemblies to indicate the satellite versions that it wants, which enables your localizations to work across assembly versions (such as if your assembly versions increment with the build - you can effectively ignore the build number).

MSDN has a lot of information on globalization and localization and how this works, even within the context of ClickOnce deployment. Check the Globalizing Windows Forms section.

Of course, if you have chosen not to rely on the .NET system for supporting globalized products, then you will have to come up with something that fits your chosen direction.

Jeff Yates
Jeff, I had to add the following to get my app to pick up the current locale. Does this look ok? Once I did this my app loads correctly when I switch my Standards and formats. It sounds like I'm all set from your post.String cultureName = System.Globalization.CultureInfo.CurrentCulture.Name; System.Globalization.CultureInfo myCI = new System.Globalization.CultureInfo(cultureName, false); System.Threading.Thread.CurrentThread.CurrentUICulture = myCI; System.Threading.Thread.CurrentThread.CurrentCulture = myCI;
Justin Holbrook
Be careful when changing the CurrentUICulture. This does not relate to resources and you should usually leave it well alone as you could break the custom settings that a user has set up for number formatting etc.
Jeff Yates