Dynamic Localization at Runtime | | |
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 | | | | re: Dynamic Localization at Runtime
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:40da76f9$1@dnews.tpgi.com.au...[color=blue]
> Hi People,
>
> I've found heaps of examples of how to localize C# apps from resource[/color]
files[color=blue]
> 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[/color]
switched[color=blue]
> 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[/color]
found[color=blue]
> anything simple enough for me yet:-).
>
> Grateful for any help.
>
> Mike
>
>[/color] | | | | re: Dynamic Localization at Runtime
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:40da76f9$1@dnews.tpgi.com.au...[color=blue]
> Hi People,
>
> I've found heaps of examples of how to localize C# apps from resource[/color]
files[color=blue]
> 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[/color]
switched[color=blue]
> 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[/color]
found[color=blue]
> anything simple enough for me yet:-).
>
> Grateful for any help.
>
> Mike
>
>[/color] |  | Similar C# / C Sharp bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,449 network members.
|