views:

777

answers:

4

I have a WinForms application which I want to translate into multiple languages. However, I do not have any experience with localizing a WinForms app, and I find very contradictory information about this subject.

Basically, what I want is:

  • In the source code, I want only one file per language
  • this file gets compiled into the main application on compilation - no satellite assemblies or external data files after building the application
  • The user can select the language, I do not need/want auto-detection based on the operating system
  • This should mainly contain strings and ints, but also a CultureInfo

Most solutions I've seen either have one .resx file per form and/or external satellite assemblies.

Do I have to roll my own? Or is there something in the framework already?

.net Framework 3.5 SP1 if that matters.

Edit: For the most part, Visual Studio already offers support for what I want, but there are two issues. When I set Form.Localizable to true I have this nice designer support, but this generates one resx per form. The idea of manually overriding it in InitializeComponent fails because it's designer-written code that will regularly be overwritten. Theoretically, I only want to a) override the creation of the ComponentResourceManager to point it to my global resx and b) change the call to ApplyResources to the overload that takes a CultureInfo as third parameter.

It seems as if I have to add a function call to my constructor thatgets called after InitializeComponent() and overrides it's behaviour. That seems terribly inefficient, but Visual Studio is right when it warns about touching InitializeComponent. At the moment, I am indeed rolling my own WinForms localization Framework...

A: 

I was asking a similar question about ASP.NET and got a first answer - this tool and its workflow might also be something for you - have a look: Lingobit Localizer

It seems to be able to load your Winforms app and allows you to start translating your labels etc. and see the forms while you do it. Lots of other features, too, like incremental translation and translation memory (if you use the same terms over and over again).

Looks quite promising (for Winforms) - haven't used it myself, though.

Here's an extensive list of potential .NET localization tools - not sure, how well they work and what they cover - have a look, maybe you'll find what you're looking for.

Marc

marc_s
Well this software creates a satellite and the OP said he does not want any satellite files.
Francis B.
Yes, I know - I was trying to show that maybe with the proper tool support, the satellite assembly approach wasn't so bad after all.
marc_s
+1  A: 

This is a huge subject and there are many ways to accomplish what you want. The framework does provide the basis but a complete solution requires that you implement certain elements yourself.

For example the default framework implementation is to create a .resx file for every resource. In ASP.Net this means each user/server control or page. This doesn't lend itself to easy maintenance and if you want to move resources to a database you need to implement your own provider.

My familiarity with Winforms is limited but if you are using Silverlight or WPF then have a read of Guy Smith-Ferrier's work on the subject at: http://www.guysmithferrier.com/category/Internationalization.aspx. He also has some toolsets that can make your life easier at: http://www.dotneti18n.com/Downloads.aspx.

I've worked with him before and have never come across anyone else with a better depth of understanding of the subject.

grenade
+1  A: 

I dont have a solution for your first and second requirement but keep in mind that localizing a form is not as simple as translating each word. You need to check that each translated text fits in their respective control. Also, maybe you have an icon or an image which need to be change in another culture.

For your point three, you can change the language manually with the following lines:

CultureInfo ci = new CultureInfo("fr");
Thread.CurrentThread.CurrentUICulture = ci;
Francis B.
A: 

For this specific application, I rolled my own. It's rather limited, but seems to be the only thing that does keep everything into the main application.

But for "proper" Localization, the built-in mechanism with Satellite Assemblies seems to be the way to go.

Michael Stum