By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,143 Members | 1,228 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,143 IT Pros & Developers. It's quick & easy.

Dynamic Localization at Runtime

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

"mike netspace.net.au>" <transam@<REMOVETHISINCLUDINGBRACKETS> wrote in
message news:40********@dnews.tpgi.com.au...
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

Nov 16 '05 #2

P: n/a
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

"mike netspace.net.au>" <transam@<REMOVETHISINCLUDINGBRACKETS> wrote in
message news:40********@dnews.tpgi.com.au...
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

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.