Dynamic Localization at Runtime

M

mike

Hi People,

I've found heaps of examples of how to localize C# apps from resource files
at runtime, but the examples I've seen all seem to involve resources that
are compiled in so that strings can be localized but not actually changed.

I want to be able to actually load the strings themselves from runtime,
doesn't matter where from, an .ini file, reg, xml file, database or
somewhere. I want to write an app where not only the locale can be switched
at runtime, but also the actual strings themselves can be configured at
runtime.

Can anyone help with some *very* simple sample code? Something just to
display a label or button would be helpful.

If this has been addressed previous in FAQ's, my apologies (I haven't found
anything simple enough for me yet:).

Grateful for any help.

Mike
 
G

Guest

Well, you can do a simple version of what .NET does, which is to simply
store all the strings in a file (xml, ini, take your pick) and then set the
..Text property of each control at runtime. But that's simplified.

What .NET does is actually sets the Location, Size, and a bunch of other
parameters for each control at runtime. You can localize your form and then
take all the code out of InitializeComponent() and place it in another
method where you can control the source of the Resources that are loaded,
but then you'll be unable to maintain the form in the Form Designer.

Basically, there's no "very" simple way to do this, though. There's a lot
more to localization than just the content of text. Keep in mind that words
differ in length in different languages, which is why you really want to
store the size and location of controls as well. For example, many of the
possessive forms in English will be shorter than Spanish or other romance
languages because of the use of the word "de" or it's variants to show
possession. In general, Spanish phrases (and I imagine other romance
languages) are about 30% longer than English equivalents, I believe. And
then German with its insanely long words, let's not even go there. And then
there are the right to left languages, if you want to support them.

Are you sure you really want to be able to configure this stuff at run-time?
I mean, if you really want to do it, the best solution in terms of being
able to do a number of forms, and keeping your application maintainable, is
probably going to be to come up with your own form design system that allows
you to configure it at runtime.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top