Multi language tooltips in Windows forms

C

coolCoder

Hi,
I am working on an application which needs localization. I am
able to localize all the controls on the form except the tool tips. I
searched alot on google, but was unable to find some sample
application. Does anyone here have an idea for implementing
localization easily for tool tips in windows forms application ?

Another question is about the procedure to implement
localization in winforms application. I have built a class library
which has a method named ApplyCulture. This method takes an argument
of form object by ref and then I iterate through controls collection
to set strings retrieved from database. This is so because I wanted to
store my key / value pairs for multilanguage in database instead of
RESX files. So now the actual question is, whether my approach is
optimal and obvious ? Or is there anything I can do to make it
optimal. Also, when you add a RESX file, how does the strings change
when you change UICulture property of current thread.

Any help would be appreciated.

Thanks,
coolCoder.
 
H

Herfried K. Wagner [MVP]

I am working on an application which needs localization. I am
able to localize all the controls on the form except the tool tips. I
searched alot on google, but was unable to find some sample
application. Does anyone here have an idea for implementing
localization easily for tool tips in windows forms application ?

I would use 'My.Resources' for this purpose. Simply copy your
project's "Resources.resx" file, rename it to "Resources.de-DE.resx"
for German resources, for example. You can use any language
identifier instead of the 'de-DE', even 'de' or 'en'. Then you can
pass 'My.Resources.SampleToolTip' in the call to your 'ToolTip'
object's 'SetToolTip' method.
Another question is about the procedure to implement
localization in winforms application. I have built a class library
which has a method named ApplyCulture. This method takes an argument
of form object by ref and then I iterate through controls collection
to set strings retrieved from database. This is so because I wanted to
store my key / value pairs for multilanguage in database instead of
RESX files. So now the actual question is, whether my approach is
optimal and obvious ? Or is there anything I can do to make it
optimal. Also, when you add a RESX file, how does the strings change
when you change UICulture property of current thread.

This is not as easy because it's impossible to determine where the
string assigned to a control comes from (which resource, to be more
precise). You'll have to store this information somewhere in order to
assign the right string to the control.
 
C

coolCoder

I would use 'My.Resources' for this purpose. Simply copy your
project's "Resources.resx" file, rename it to "Resources.de-DE.resx"
for German resources, for example. You can use any language
identifier instead of the 'de-DE', even 'de' or 'en'. Then you can
pass 'My.Resources.SampleToolTip' in the call to your 'ToolTip'
object's 'SetToolTip' method.


This is not as easy because it's impossible to determine where the
string assigned to a control comes from (which resource, to be more
precise). You'll have to store this information somewhere in order to
assign the right string to the control.

Hi Herfried,
First of all, thanks for your reply. Actually I have
extended the ResourceManager class so that I have a new class called
ResourceManagerSql. This class does have GetString() method which
returns me correct string value for a key passed as an argument. Now
let me clear my questions a bit.

1. I have described that I am iterating through controls collections
and there child controls to change the strings when user switches
language. <User can switch language using a button> So, I wanted to
know, how the strings are changed when you use RESX files ?
Automatically or whether the IDE (VS.NET 2005) writes code for
changing these strings some where ? If I am totally lost on the topic,
please let me know the exact procedure to extend the ResourceManager
class so that strings automatically change when I set the UICulture of
current thread.

2. Now the second question is related to the first. Since tool tip is
a control extender, I am not able to access ToolTip property from
code itself. So imagine a class library, which iterates through each
and every control and changes the strings as it finds those in the
database. How can I set ToolTips in this fashion ? Whether my approach
is correct or not ?

I did not find any material for extending the ResourceManager class.
Can you please point me to some useful link ?

Thanks,
coolCoder
 

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