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
andints
, but also aCultureInfo
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 globalresx
and - b) change the call to
ApplyResources
to the overload that takes aCultureInfo
as third parameter.
It seems as if I have to add a function call to my constructor that gets called after InitializeComponent()
and overrides its 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
...
geometrically
not exponentially. :) the number of languages is a multiplier, not an exponent. :) :) the REASON there is oneresx
per language per form is that for a specific language the form size may have to change, control placements may have to change, the icons may have to change, basically ANYTHING about the form may have to change on a per-language basis. So the RESX file has to multiply regardless. The strings are in the same file for that form as everything else specific to that form. – Ency